diff --git a/dp/cumulative-sum.hpp b/dp/cumulative-sum.hpp index d8a5a085c..1306c6272 100644 --- a/dp/cumulative-sum.hpp +++ b/dp/cumulative-sum.hpp @@ -6,7 +6,7 @@ struct CumulativeSum { explicit CumulativeSum(size_t sz) : data(sz + 1, 0) {} - void add(int k, const T &x) { data[k + 1] += x; } + void add(int k, const T& x) { data[k + 1] += x; } void build() { for (int i = 1; i < data.size(); i++) { diff --git a/dp/divide-and-conquer-optimization.hpp b/dp/divide-and-conquer-optimization.hpp index c64c47848..a59d448aa 100644 --- a/dp/divide-and-conquer-optimization.hpp +++ b/dp/divide-and-conquer-optimization.hpp @@ -2,8 +2,8 @@ template > vector > divide_and_conquer_optimization( - int H, int W, T INF, const function &f, - const Compare &comp = Compare()) { + int H, int W, T INF, const function& f, + const Compare& comp = Compare()) { vector > dp(H + 1, vector(W + 1, INF)); dp[0][0] = 0; for (int i = 1; i <= H; i++) { diff --git a/dp/edit-distance.hpp b/dp/edit-distance.hpp index ba85cf538..1e248462e 100644 --- a/dp/edit-distance.hpp +++ b/dp/edit-distance.hpp @@ -1,4 +1,4 @@ -int edit_distance(const string &S, const string &T) { +int edit_distance(const string& S, const string& T) { const int N = (int)S.size(), M = (int)T.size(); vector > dp(N + 1, vector(M + 1, N + M)); for (int i = 0; i <= N; i++) dp[i][0] = i; diff --git a/dp/knapsack-01-2.hpp b/dp/knapsack-01-2.hpp index 9496e0c9e..682ea4759 100644 --- a/dp/knapsack-01-2.hpp +++ b/dp/knapsack-01-2.hpp @@ -1,5 +1,5 @@ template -T knapsack_01_2(const vector &w, const vector &v, const T &W) { +T knapsack_01_2(const vector& w, const vector& v, const T& W) { const int N = (int)w.size(); const int sum = accumulate(begin(v), end(v), 0); vector dp(sum + 1, W + 1); diff --git a/dp/knapsack-01.hpp b/dp/knapsack-01.hpp index 5826dcaf2..d633793af 100644 --- a/dp/knapsack-01.hpp +++ b/dp/knapsack-01.hpp @@ -1,6 +1,6 @@ template > -vector knapsack_01(const vector &w, const vector &v, const int &W, - const T &NG, const Compare &comp = Compare()) { +vector knapsack_01(const vector& w, const vector& v, const int& W, + const T& NG, const Compare& comp = Compare()) { const int N = (int)w.size(); vector dp(W + 1, NG); dp[0] = T(); diff --git a/dp/knapsack-limitations-2.hpp b/dp/knapsack-limitations-2.hpp index 2df89d2ec..c29ae4b62 100644 --- a/dp/knapsack-limitations-2.hpp +++ b/dp/knapsack-limitations-2.hpp @@ -1,8 +1,8 @@ #include "knapsack-limitations.hpp" template -T knapsack_limitations(const vector &w, const vector &m, - const vector &v, const T &W) { +T knapsack_limitations(const vector& w, const vector& m, + const vector& v, const T& W) { const int N = (int)w.size(); auto v_max = *max_element(begin(v), end(v)); if (v_max == 0) return 0; @@ -23,7 +23,7 @@ T knapsack_limitations(const vector &w, const vector &m, for (int i = 0; i < dp.size(); i++) { if (dp[i] > W || dp[i] == -1) continue; T rest = W - dp[i], cost = i; - for (auto &p : ord) { + for (auto& p : ord) { auto get = min(mb[p], rest / w[p]); if (get <= 0) continue; cost += get * v[p]; diff --git a/dp/knapsack-limitations.hpp b/dp/knapsack-limitations.hpp index 8fb3166d7..d5298465c 100644 --- a/dp/knapsack-limitations.hpp +++ b/dp/knapsack-limitations.hpp @@ -1,7 +1,7 @@ template > -vector knapsack_limitations(const vector &w, const vector &m, - const vector &v, const int &W, const T &NG, - const Compare &comp = Compare()) { +vector knapsack_limitations(const vector& w, const vector& m, + const vector& v, const int& W, const T& NG, + const Compare& comp = Compare()) { const int N = (int)w.size(); vector dp(W + 1, NG), deqv(W + 1); dp[0] = T(); diff --git a/dp/knapsack.hpp b/dp/knapsack.hpp index 5bf7f9c75..2092b7b7c 100644 --- a/dp/knapsack.hpp +++ b/dp/knapsack.hpp @@ -1,6 +1,6 @@ template > -vector knapsack(const vector &w, const vector &v, const int &W, - const T &NG, const Compare &comp = Compare()) { +vector knapsack(const vector& w, const vector& v, const int& W, + const T& NG, const Compare& comp = Compare()) { const int N = (int)w.size(); vector dp(W + 1, NG); dp[0] = T(); diff --git a/dp/longest-increasing-subsequence.hpp b/dp/longest-increasing-subsequence.hpp index 20fcdf622..631e5b4be 100644 --- a/dp/longest-increasing-subsequence.hpp +++ b/dp/longest-increasing-subsequence.hpp @@ -1,7 +1,7 @@ template -size_t longest_increasing_subsequence(const vector &a, bool strict) { +size_t longest_increasing_subsequence(const vector& a, bool strict) { vector lis; - for (auto &p : a) { + for (auto& p : a) { typename vector::iterator it; if (strict) it = lower_bound(begin(lis), end(lis), p); diff --git a/dp/monotone-minima.hpp b/dp/monotone-minima.hpp index 7c0d5d0b3..894a79f0f 100644 --- a/dp/monotone-minima.hpp +++ b/dp/monotone-minima.hpp @@ -1,7 +1,7 @@ template > vector > monotone_minima(int H, int W, - const function &f, - const Compare &comp = Compare()) { + const function& f, + const Compare& comp = Compare()) { vector > dp(H); function dfs = [&](int top, int bottom, int left, int right) { diff --git a/dp/online-offline-dp.hpp b/dp/online-offline-dp.hpp index 7aa885ce9..f48b9a8a7 100644 --- a/dp/online-offline-dp.hpp +++ b/dp/online-offline-dp.hpp @@ -1,8 +1,8 @@ #include "monotone-minima.hpp" template > -vector online_offline_dp(int W, const function &f, - const Compare &comp = Compare()) { +vector online_offline_dp(int W, const function& f, + const Compare& comp = Compare()) { vector dp(W + 1); vector isset(W + 1); int y_base = -1, x_base = -1; diff --git a/geometry/angle.hpp b/geometry/angle.hpp index 41aaf0f4b..c8d3789e5 100644 --- a/geometry/angle.hpp +++ b/geometry/angle.hpp @@ -1,12 +1,12 @@ #include "point.hpp" namespace geometry { -Real radian_to_degree(const Real &theta) { return theta * 180.0 / PI; } +Real radian_to_degree(const Real& theta) { return theta * 180.0 / PI; } -Real degree_to_radian(const Real °) { return deg * PI / 180.0; } +Real degree_to_radian(const Real& deg) { return deg * PI / 180.0; } // smaller angle of the a-b-c -Real get_smaller_angle(const Point &a, const Point &b, const Point &c) { +Real get_smaller_angle(const Point& a, const Point& b, const Point& c) { const Point v(a - b), w(c - b); auto alpha = atan2(imag(v), real(v)); auto beta = atan2(imag(w), real(w)); diff --git a/geometry/area.hpp b/geometry/area.hpp index c39298cf0..8c2774a16 100644 --- a/geometry/area.hpp +++ b/geometry/area.hpp @@ -3,7 +3,7 @@ namespace geometry { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_A -Real area(const Polygon &p) { +Real area(const Polygon& p) { int n = (int)p.size(); Real A = 0; for (int i = 0; i < n; ++i) { diff --git a/geometry/base.hpp b/geometry/base.hpp index c2037d15b..291d2ea8f 100644 --- a/geometry/base.hpp +++ b/geometry/base.hpp @@ -7,7 +7,7 @@ const Real PI = acos(static_cast(-1)); enum { OUT, ON, IN }; -inline int sign(const Real &r) { return r <= -EPS ? -1 : r >= EPS ? 1 : 0; } +inline int sign(const Real& r) { return r <= -EPS ? -1 : r >= EPS ? 1 : 0; } -inline bool equals(const Real &a, const Real &b) { return sign(a - b) == 0; } +inline bool equals(const Real& a, const Real& b) { return sign(a - b) == 0; } } // namespace geometry diff --git a/geometry/ccw.hpp b/geometry/ccw.hpp index 4405340fa..976729f8e 100644 --- a/geometry/ccw.hpp +++ b/geometry/ccw.hpp @@ -8,7 +8,7 @@ constexpr int CLOCKWISE = -1; constexpr int ONLINE_BACK = +2; // c-a-b constexpr int ONLINE_FRONT = -2; // a-b-c constexpr int ON_SEGMENT = 0; // a-c-b -int ccw(const Point &a, Point b, Point c) { +int ccw(const Point& a, Point b, Point c) { b = b - a, c = c - a; if (sign(cross(b, c)) == +1) return COUNTER_CLOCKWISE; if (sign(cross(b, c)) == -1) return CLOCKWISE; diff --git a/geometry/circle.hpp b/geometry/circle.hpp index e881009eb..179ab8825 100644 --- a/geometry/circle.hpp +++ b/geometry/circle.hpp @@ -8,7 +8,7 @@ struct Circle { Circle() = default; - Circle(const Point &p, const Real &r) : p(p), r(r) {} + Circle(const Point& p, const Real& r) : p(p), r(r) {} }; using Circles = vector; diff --git a/geometry/common_area_cp.hpp b/geometry/common_area_cp.hpp index 15361bafa..7c4baef4b 100644 --- a/geometry/common_area_cp.hpp +++ b/geometry/common_area_cp.hpp @@ -7,7 +7,7 @@ namespace geometry { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_H -Real ca_cp_impl(const Circle &c, const Point &a, const Point &b) { +Real ca_cp_impl(const Circle& c, const Point& a, const Point& b) { auto va = c.p - a, vb = c.p - b; Real f = cross(va, vb), ret = 0; if (sign(f) == 0) return ret; @@ -27,7 +27,7 @@ Real ca_cp_impl(const Circle &c, const Point &a, const Point &b) { return ret; } -Real common_area_cp(const Circle &c, const Polygon &p) { +Real common_area_cp(const Circle& c, const Polygon& p) { if (p.size() < 3) return 0; Real A = 0; for (int i = 0; i < p.size(); i++) { diff --git a/geometry/contains.hpp b/geometry/contains.hpp index 6819550ed..0a006b59b 100644 --- a/geometry/contains.hpp +++ b/geometry/contains.hpp @@ -4,7 +4,7 @@ namespace geometry { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_C -int contains(const Polygon &Q, const Point &p) { +int contains(const Polygon& Q, const Point& p) { bool in = false; for (int i = 0; i < Q.size(); i++) { Point a = Q[i] - p, b = Q[(i + 1) % Q.size()] - p; diff --git a/geometry/convex_hull.hpp b/geometry/convex_hull.hpp index 3ae81d7c2..19321912b 100644 --- a/geometry/convex_hull.hpp +++ b/geometry/convex_hull.hpp @@ -4,7 +4,7 @@ namespace geometry { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_A -Polygon convex_hull(Polygon &p, bool strict = true) { +Polygon convex_hull(Polygon& p, bool strict = true) { int n = (int)p.size(), k = 0; if (n <= 2) return p; sort(begin(p), end(p), compare_x); diff --git a/geometry/convex_polygon_contains.hpp b/geometry/convex_polygon_contains.hpp index dd30e4795..94dcbe976 100644 --- a/geometry/convex_polygon_contains.hpp +++ b/geometry/convex_polygon_contains.hpp @@ -3,7 +3,7 @@ #include "polygon.hpp" namespace geometry { -int convex_polygon_contains(const Polygon &Q, const Point &p) { +int convex_polygon_contains(const Polygon& Q, const Point& p) { int N = (int)Q.size(); Point g = (Q[0] + Q[N / 3] + Q[N * 2 / 3]) / 3.0; if (equals(imag(g), imag(p)) && equals(real(g), real(p))) return IN; diff --git a/geometry/convex_polygon_cut.hpp b/geometry/convex_polygon_cut.hpp index 0378d8608..0f0cc8837 100644 --- a/geometry/convex_polygon_cut.hpp +++ b/geometry/convex_polygon_cut.hpp @@ -7,11 +7,11 @@ namespace geometry { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_C // cut with a straight line l and return a convex polygon on the left -Polygon convex_polygon_cut(const Polygon &U, const Line &l) { +Polygon convex_polygon_cut(const Polygon& U, const Line& l) { Polygon ret; for (int i = 0; i < U.size(); i++) { - const Point &now = U[i]; - const Point &nxt = U[(i + 1) % U.size()]; + const Point& now = U[i]; + const Point& nxt = U[(i + 1) % U.size()]; auto cf = cross(l.a - now, l.b - now); auto cs = cross(l.a - nxt, l.b - nxt); if (sign(cf) >= 0) { diff --git a/geometry/convex_polygon_diameter.hpp b/geometry/convex_polygon_diameter.hpp index 7b2603c52..095b25a08 100644 --- a/geometry/convex_polygon_diameter.hpp +++ b/geometry/convex_polygon_diameter.hpp @@ -3,7 +3,7 @@ namespace geometry { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_B -pair convex_polygon_diameter(const Polygon &p) { +pair convex_polygon_diameter(const Polygon& p) { int N = (int)p.size(); int is = 0, js = 0; for (int i = 1; i < N; i++) { diff --git a/geometry/cross_point_cc.hpp b/geometry/cross_point_cc.hpp index 09ada4576..a9a989e5e 100644 --- a/geometry/cross_point_cc.hpp +++ b/geometry/cross_point_cc.hpp @@ -4,7 +4,7 @@ namespace geometry { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_E -Points cross_point_cc(const Circle &c1, const Circle &c2) { +Points cross_point_cc(const Circle& c1, const Circle& c2) { Real d = abs(c1.p - c2.p), r = c1.r + c2.r; if (sign(d - r) > 0 or sign(d + c1.r - c2.r) < 0) return {}; Real a = acos((norm(c1.r) - norm(c2.r) + norm(d)) / (2 * c1.r * d)); diff --git a/geometry/cross_point_cl.hpp b/geometry/cross_point_cl.hpp index 9da678e55..9e6660b4c 100644 --- a/geometry/cross_point_cl.hpp +++ b/geometry/cross_point_cl.hpp @@ -6,7 +6,7 @@ namespace geometry { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_D -Points cross_point_cl(const Circle &c, const Line &l) { +Points cross_point_cl(const Circle& c, const Line& l) { Point pr = projection(l, c.p); if (equals(abs(pr - c.p), c.r)) return {pr}; Point e = (l.b - l.a) / abs(l.b - l.a); diff --git a/geometry/cross_point_cs.hpp b/geometry/cross_point_cs.hpp index ac8120076..be0b44fa4 100644 --- a/geometry/cross_point_cs.hpp +++ b/geometry/cross_point_cs.hpp @@ -5,7 +5,7 @@ #include "segment.hpp" namespace geometry { -Points cross_point_cs(const Circle &c, const Segment &s) { +Points cross_point_cs(const Circle& c, const Segment& s) { int num = is_intersect_cs(c, s); if (num == 0) return {}; if (num == 2) return cross_point_cl(c, s); diff --git a/geometry/cross_point_ll.hpp b/geometry/cross_point_ll.hpp index f83d67715..7777bf42e 100644 --- a/geometry/cross_point_ll.hpp +++ b/geometry/cross_point_ll.hpp @@ -2,7 +2,7 @@ #include "line.hpp" namespace geometry { -Point cross_point_ll(const Line &l, const Line &m) { +Point cross_point_ll(const Line& l, const Line& m) { Real A = cross(l.b - l.a, m.b - m.a); Real B = cross(l.b - l.a, l.b - m.a); if (equals(abs(A), 0) && equals(abs(B), 0)) return m.a; diff --git a/geometry/distance_ll.hpp b/geometry/distance_ll.hpp index 21ec456b1..422f50df2 100644 --- a/geometry/distance_ll.hpp +++ b/geometry/distance_ll.hpp @@ -3,7 +3,7 @@ #include "line.hpp" namespace geometry { -Real distance_ll(const Line &l, const Line &m) { +Real distance_ll(const Line& l, const Line& m) { return is_intersect_ll(l, m) ? 0 : distance_lp(l, m.a); } } // namespace geometry diff --git a/geometry/distance_lp.hpp b/geometry/distance_lp.hpp index 885cbc477..39cd098e5 100644 --- a/geometry/distance_lp.hpp +++ b/geometry/distance_lp.hpp @@ -2,7 +2,7 @@ #include "projection.hpp" namespace geometry { -Real distance_lp(const Line &l, const Point &p) { +Real distance_lp(const Line& l, const Point& p) { return abs(p - projection(l, p)); } } // namespace geometry diff --git a/geometry/distance_pp.hpp b/geometry/distance_pp.hpp index 5fc00da15..be81c8d01 100644 --- a/geometry/distance_pp.hpp +++ b/geometry/distance_pp.hpp @@ -1,5 +1,5 @@ #include "point.hpp" namespace geometry { -Real distance(const Point &a, const Point &b) { return abs(a - b); } +Real distance(const Point& a, const Point& b) { return abs(a - b); } } // namespace geometry diff --git a/geometry/distance_sp.hpp b/geometry/distance_sp.hpp index da98c872c..6abc5adc3 100644 --- a/geometry/distance_sp.hpp +++ b/geometry/distance_sp.hpp @@ -4,7 +4,7 @@ #include "segment.hpp" namespace geometry { -Real distance_sp(const Segment &s, const Point &p) { +Real distance_sp(const Segment& s, const Point& p) { Point r = projection(s, p); if (is_intersect_sp(s, r)) return abs(r - p); return min(abs(s.a - p), abs(s.b - p)); diff --git a/geometry/distance_ss.hpp b/geometry/distance_ss.hpp index c4b385c38..0621b5bdd 100644 --- a/geometry/distance_ss.hpp +++ b/geometry/distance_ss.hpp @@ -4,7 +4,7 @@ namespace geometry { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_D -Real distance_ss(const Segment &a, const Segment &b) { +Real distance_ss(const Segment& a, const Segment& b) { if (is_intersect_ss(a, b)) return 0; return min({distance_sp(a, b.a), distance_sp(a, b.b), distance_sp(b, a.a), distance_sp(b, a.b)}); diff --git a/geometry/is_convex_polygon.hpp b/geometry/is_convex_polygon.hpp index 969a2e8f9..6d8b2c633 100644 --- a/geometry/is_convex_polygon.hpp +++ b/geometry/is_convex_polygon.hpp @@ -4,7 +4,7 @@ namespace geometry { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_B -bool is_convex_polygon(const Polygon &p) { +bool is_convex_polygon(const Polygon& p) { int n = (int)p.size(); for (int i = 0; i < n; i++) { if (ccw(p[(i + n - 1) % n], p[i], p[(i + 1) % n]) == CLOCKWISE) diff --git a/geometry/is_intersect_cl.hpp b/geometry/is_intersect_cl.hpp index da6662fad..ff6d4ba61 100644 --- a/geometry/is_intersect_cl.hpp +++ b/geometry/is_intersect_cl.hpp @@ -4,7 +4,7 @@ #include "line.hpp" namespace geometry { -bool is_intersect_cl(const Circle &c, const Line &l) { +bool is_intersect_cl(const Circle& c, const Line& l) { return sign(c.r - distance_lp(l, c.p)) >= 0; } } // namespace geometry diff --git a/geometry/is_intersect_cp.hpp b/geometry/is_intersect_cp.hpp index 89b9673dc..4c6d8176e 100644 --- a/geometry/is_intersect_cp.hpp +++ b/geometry/is_intersect_cp.hpp @@ -3,7 +3,7 @@ #include "point.hpp" namespace geometry { -bool is_intersect_cp(const Circle &c, const Point &p) { +bool is_intersect_cp(const Circle& c, const Point& p) { return equals(abs(p - c.p) - c.r, 0); } } // namespace geometry diff --git a/geometry/is_intersect_cs.hpp b/geometry/is_intersect_cs.hpp index 685c9b619..a277a296a 100644 --- a/geometry/is_intersect_cs.hpp +++ b/geometry/is_intersect_cs.hpp @@ -5,7 +5,7 @@ #include "segment.hpp" namespace geometry { -int is_intersect_cs(const Circle &c, const Segment &l) { +int is_intersect_cs(const Circle& c, const Segment& l) { Point h = projection(l, c.p); if (sign(norm(h - c.p) - norm(c.r)) > 0) return 0; auto d1 = abs(c.p - l.a), d2 = abs(c.p - l.b); diff --git a/geometry/is_intersect_ll.hpp b/geometry/is_intersect_ll.hpp index f5780ba0a..2607bbb22 100644 --- a/geometry/is_intersect_ll.hpp +++ b/geometry/is_intersect_ll.hpp @@ -2,7 +2,7 @@ #include "line.hpp" namespace geometry { -bool is_intersect_ll(const Line &l, const Line &m) { +bool is_intersect_ll(const Line& l, const Line& m) { Real A = cross(l.b - l.a, m.b - m.a); Real B = cross(l.b - l.a, l.b - m.a); if (equals(abs(A), 0) && equals(abs(B), 0)) return true; diff --git a/geometry/is_intersect_lp.hpp b/geometry/is_intersect_lp.hpp index 5e8b263fa..183c68bae 100644 --- a/geometry/is_intersect_lp.hpp +++ b/geometry/is_intersect_lp.hpp @@ -3,7 +3,7 @@ #include "point.hpp" namespace geometry { -bool is_intersect_lp(const Line &l, const Point &p) { +bool is_intersect_lp(const Line& l, const Point& p) { return abs(ccw(l.a, l.b, p)) != 1; } } // namespace geometry diff --git a/geometry/is_intersect_ls.hpp b/geometry/is_intersect_ls.hpp index 3dc135b87..be0d1ac8e 100644 --- a/geometry/is_intersect_ls.hpp +++ b/geometry/is_intersect_ls.hpp @@ -4,7 +4,7 @@ #include "segment.hpp" namespace geometry { -bool is_intersect_ls(const Line &l, const Segment &s) { +bool is_intersect_ls(const Line& l, const Segment& s) { return sign(cross(l.b - l.a, s.a - l.a)) * sign(cross(l.b - l.a, s.b - l.a)) <= 0; diff --git a/geometry/is_intersect_sp.hpp b/geometry/is_intersect_sp.hpp index 4d437713b..2f8b3ed81 100644 --- a/geometry/is_intersect_sp.hpp +++ b/geometry/is_intersect_sp.hpp @@ -3,7 +3,7 @@ #include "segment.hpp" namespace geometry { -bool is_intersect_sp(const Segment &s, const Point &p) { +bool is_intersect_sp(const Segment& s, const Point& p) { return ccw(s.a, s.b, p) == ON_SEGMENT; } } // namespace geometry diff --git a/geometry/is_intersect_ss.hpp b/geometry/is_intersect_ss.hpp index 6519e6967..868a1b2fd 100644 --- a/geometry/is_intersect_ss.hpp +++ b/geometry/is_intersect_ss.hpp @@ -3,7 +3,7 @@ #include "segment.hpp" namespace geometry { -bool is_intersect_ss(const Segment &s, const Segment &t) { +bool is_intersect_ss(const Segment& s, const Segment& t) { return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0; } diff --git a/geometry/is_orthogonal.hpp b/geometry/is_orthogonal.hpp index 6aa3f6f38..76b128f94 100644 --- a/geometry/is_orthogonal.hpp +++ b/geometry/is_orthogonal.hpp @@ -3,7 +3,7 @@ namespace geometry { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A -bool is_orthogonal(const Line &a, const Line &b) { +bool is_orthogonal(const Line& a, const Line& b) { return equals(dot(a.a - a.b, b.a - b.b), 0.0); } } // namespace geometry diff --git a/geometry/is_parallel.hpp b/geometry/is_parallel.hpp index 219787feb..a43b48023 100644 --- a/geometry/is_parallel.hpp +++ b/geometry/is_parallel.hpp @@ -3,7 +3,7 @@ namespace geometry { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A -bool is_parallel(const Line &a, const Line &b) { +bool is_parallel(const Line& a, const Line& b) { return equals(cross(a.b - a.a, b.b - b.a), 0.0); } } // namespace geometry diff --git a/geometry/line.hpp b/geometry/line.hpp index 9a0edd7a8..e3f6928cf 100644 --- a/geometry/line.hpp +++ b/geometry/line.hpp @@ -7,9 +7,9 @@ struct Line { Line() = default; - Line(const Point &a, const Point &b) : a(a), b(b) {} + Line(const Point& a, const Point& b) : a(a), b(b) {} - Line(const Real &A, const Real &B, const Real &C) { // Ax+By=C + Line(const Real& A, const Real& B, const Real& C) { // Ax+By=C if (equals(A, 0)) { assert(!equals(B, 0)); a = Point(0, C / B); @@ -26,11 +26,11 @@ struct Line { } } - friend ostream &operator<<(ostream &os, Line &l) { + friend ostream& operator<<(ostream& os, Line& l) { return os << l.a << " to " << l.b; } - friend istream &operator>>(istream &is, Line &l) { return is >> l.a >> l.b; } + friend istream& operator>>(istream& is, Line& l) { return is >> l.a >> l.b; } }; using Lines = vector; diff --git a/geometry/point.hpp b/geometry/point.hpp index b64727bbd..ff67aefde 100644 --- a/geometry/point.hpp +++ b/geometry/point.hpp @@ -4,40 +4,40 @@ namespace geometry { using Point = complex; -istream &operator>>(istream &is, Point &p) { +istream& operator>>(istream& is, Point& p) { Real a, b; is >> a >> b; p = Point(a, b); return is; } -ostream &operator<<(ostream &os, const Point &p) { +ostream& operator<<(ostream& os, const Point& p) { return os << real(p) << " " << imag(p); } -Point operator*(const Point &p, const Real &d) { +Point operator*(const Point& p, const Real& d) { return Point(real(p) * d, imag(p) * d); } // rotate point p counterclockwise by theta rad -Point rotate(Real theta, const Point &p) { +Point rotate(Real theta, const Point& p) { return Point(cos(theta) * real(p) - sin(theta) * imag(p), sin(theta) * real(p) + cos(theta) * imag(p)); } -Real cross(const Point &a, const Point &b) { +Real cross(const Point& a, const Point& b) { return real(a) * imag(b) - imag(a) * real(b); } -Real dot(const Point &a, const Point &b) { +Real dot(const Point& a, const Point& b) { return real(a) * real(b) + imag(a) * imag(b); } -bool compare_x(const Point &a, const Point &b) { +bool compare_x(const Point& a, const Point& b) { return equals(real(a), real(b)) ? imag(a) < imag(b) : real(a) < real(b); } -bool compare_y(const Point &a, const Point &b) { +bool compare_y(const Point& a, const Point& b) { return equals(imag(a), imag(b)) ? real(a) < real(b) : imag(a) < imag(b); } diff --git a/geometry/projection.hpp b/geometry/projection.hpp index 2ea03b498..b256811c5 100644 --- a/geometry/projection.hpp +++ b/geometry/projection.hpp @@ -5,7 +5,7 @@ namespace geometry { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A -Point projection(const Line &l, const Point &p) { +Point projection(const Line& l, const Point& p) { auto t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b); return l.a + (l.a - l.b) * t; } diff --git a/geometry/reflection.hpp b/geometry/reflection.hpp index d45790bd6..d513ce92e 100644 --- a/geometry/reflection.hpp +++ b/geometry/reflection.hpp @@ -4,7 +4,7 @@ namespace geometry { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_B -Point reflection(const Line &l, const Point &p) { +Point reflection(const Line& l, const Point& p) { return p + (projection(l, p) - p) * 2; } } // namespace geometry diff --git a/geometry/template.hpp b/geometry/template.hpp index a75ec2354..d188b20a7 100644 --- a/geometry/template.hpp +++ b/geometry/template.hpp @@ -4,23 +4,23 @@ const Real EPS = 1e-8, PI = acos(-1); inline bool eq(Real a, Real b) { return fabs(b - a) < EPS; } -Point operator*(const Point &p, const Real &d) { +Point operator*(const Point& p, const Real& d) { return Point(real(p) * d, imag(p) * d); } -istream &operator>>(istream &is, Point &p) { +istream& operator>>(istream& is, Point& p) { Real a, b; is >> a >> b; p = Point(a, b); return is; } -ostream &operator<<(ostream &os, Point &p) { +ostream& operator<<(ostream& os, Point& p) { return os << fixed << setprecision(10) << p.real() << " " << p.imag(); } // rotate point p counterclockwise by theta rad -Point rotate(Real theta, const Point &p) { +Point rotate(Real theta, const Point& p) { return Point(cos(theta) * p.real() - sin(theta) * p.imag(), sin(theta) * p.real() + cos(theta) * p.imag()); } @@ -30,7 +30,7 @@ Real radian_to_degree(Real r) { return (r * 180.0 / PI); } Real degree_to_radian(Real d) { return (d * PI / 180.0); } // smaller angle of the a-b-c -Real get_angle(const Point &a, const Point &b, const Point &c) { +Real get_angle(const Point& a, const Point& b, const Point& c) { const Point v(b - a), w(c - b); Real alpha = atan2(v.imag(), v.real()), beta = atan2(w.imag(), w.real()); if (alpha > beta) swap(alpha, beta); @@ -39,7 +39,7 @@ Real get_angle(const Point &a, const Point &b, const Point &c) { } namespace std { -bool operator<(const Point &a, const Point &b) { +bool operator<(const Point& a, const Point& b) { return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag(); } } // namespace std @@ -61,11 +61,11 @@ struct Line { a = Point(0, C / B), b = Point(C / A, 0); } - friend ostream &operator<<(ostream &os, Line &p) { + friend ostream& operator<<(ostream& os, Line& p) { return os << p.a << " to " << p.b; } - friend istream &operator>>(istream &is, Line &a) { return is >> a.a >> a.b; } + friend istream& operator>>(istream& is, Line& a) { return is >> a.a >> a.b; } }; struct Segment : Line { @@ -89,16 +89,16 @@ using Segments = vector; using Lines = vector; using Circles = vector; -Real cross(const Point &a, const Point &b) { +Real cross(const Point& a, const Point& b) { return real(a) * imag(b) - imag(a) * real(b); } -Real dot(const Point &a, const Point &b) { +Real dot(const Point& a, const Point& b) { return real(a) * real(b) + imag(a) * imag(b); } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C -int ccw(const Point &a, Point b, Point c) { +int ccw(const Point& a, Point b, Point c) { b = b - a, c = c - a; if (cross(b, c) > EPS) return +1; // "COUNTER_CLOCKWISE" if (cross(b, c) < -EPS) return -1; // "CLOCKWISE" @@ -108,65 +108,65 @@ int ccw(const Point &a, Point b, Point c) { } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A -bool parallel(const Line &a, const Line &b) { +bool parallel(const Line& a, const Line& b) { return eq(cross(a.b - a.a, b.b - b.a), 0.0); } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A -bool orthogonal(const Line &a, const Line &b) { +bool orthogonal(const Line& a, const Line& b) { return eq(dot(a.a - a.b, b.a - b.b), 0.0); } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A -Point projection(const Line &l, const Point &p) { +Point projection(const Line& l, const Point& p) { double t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b); return l.a + (l.a - l.b) * t; } -Point projection(const Segment &l, const Point &p) { +Point projection(const Segment& l, const Point& p) { double t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b); return l.a + (l.a - l.b) * t; } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_B -Point reflection(const Line &l, const Point &p) { +Point reflection(const Line& l, const Point& p) { return p + (projection(l, p) - p) * 2.0; } -bool intersect(const Line &l, const Point &p) { +bool intersect(const Line& l, const Point& p) { return abs(ccw(l.a, l.b, p)) != 1; } -bool intersect(const Line &l, const Line &m) { +bool intersect(const Line& l, const Line& m) { return abs(cross(l.b - l.a, m.b - m.a)) > EPS || abs(cross(l.b - l.a, m.b - l.a)) < EPS; } -bool intersect(const Segment &s, const Point &p) { +bool intersect(const Segment& s, const Point& p) { return ccw(s.a, s.b, p) == 0; } -bool intersect(const Line &l, const Segment &s) { +bool intersect(const Line& l, const Segment& s) { return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < EPS; } -Real distance(const Line &l, const Point &p); +Real distance(const Line& l, const Point& p); -bool intersect(const Circle &c, const Line &l) { +bool intersect(const Circle& c, const Line& l) { return distance(l, c.p) <= c.r + EPS; } -bool intersect(const Circle &c, const Point &p) { +bool intersect(const Circle& c, const Point& p) { return abs(abs(p - c.p) - c.r) < EPS; } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_B -bool intersect(const Segment &s, const Segment &t) { +bool intersect(const Segment& s, const Segment& t) { return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0; } -int intersect(const Circle &c, const Segment &l) { +int intersect(const Circle& c, const Segment& l) { if (norm(projection(l, c.p) - c.p) - c.r * c.r > EPS) return 0; auto d1 = abs(c.p - l.a), d2 = abs(c.p - l.b); if (d1 < c.r + EPS && d2 < c.r + EPS) return 0; @@ -188,35 +188,35 @@ int intersect(Circle c1, Circle c2) { return 0; } -Real distance(const Point &a, const Point &b) { return abs(a - b); } +Real distance(const Point& a, const Point& b) { return abs(a - b); } -Real distance(const Line &l, const Point &p) { +Real distance(const Line& l, const Point& p) { return abs(p - projection(l, p)); } -Real distance(const Line &l, const Line &m) { +Real distance(const Line& l, const Line& m) { return intersect(l, m) ? 0 : distance(l, m.a); } -Real distance(const Segment &s, const Point &p) { +Real distance(const Segment& s, const Point& p) { Point r = projection(s, p); if (intersect(s, r)) return abs(r - p); return min(abs(s.a - p), abs(s.b - p)); } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_D -Real distance(const Segment &a, const Segment &b) { +Real distance(const Segment& a, const Segment& b) { if (intersect(a, b)) return 0; return min( {distance(a, b.a), distance(a, b.b), distance(b, a.a), distance(b, a.b)}); } -Real distance(const Line &l, const Segment &s) { +Real distance(const Line& l, const Segment& s) { if (intersect(l, s)) return 0; return min(distance(l, s.a), distance(l, s.b)); } -Point crosspoint(const Line &l, const Line &m) { +Point crosspoint(const Line& l, const Line& m) { Real A = cross(l.b - l.a, m.b - m.a); Real B = cross(l.b - l.a, l.b - m.a); if (eq(abs(A), 0.0) && eq(abs(B), 0.0)) return m.a; @@ -224,12 +224,12 @@ Point crosspoint(const Line &l, const Line &m) { } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_C -Point crosspoint(const Segment &l, const Segment &m) { +Point crosspoint(const Segment& l, const Segment& m) { return crosspoint(Line(l), Line(m)); } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_D -pair crosspoint(const Circle &c, const Line l) { +pair crosspoint(const Circle& c, const Line l) { Point pr = projection(l, c.p); Point e = (l.b - l.a) / abs(l.b - l.a); if (eq(distance(l, c.p), c.r)) return {pr, pr}; @@ -237,7 +237,7 @@ pair crosspoint(const Circle &c, const Line l) { return {pr - e * base, pr + e * base}; } -pair crosspoint(const Circle &c, const Segment &l) { +pair crosspoint(const Circle& c, const Segment& l) { Line aa = Line(l.a, l.b); if (intersect(c, l) == 2) return crosspoint(c, aa); auto ret = crosspoint(c, aa); @@ -249,7 +249,7 @@ pair crosspoint(const Circle &c, const Segment &l) { } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_E -pair crosspoint(const Circle &c1, const Circle &c2) { +pair crosspoint(const Circle& c1, const Circle& c2) { Real d = abs(c1.p - c2.p); Real a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d)); Real t = atan2(c2.p.imag() - c1.p.imag(), c2.p.real() - c1.p.real()); @@ -260,7 +260,7 @@ pair crosspoint(const Circle &c1, const Circle &c2) { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_F // tangent of circle c through point p -pair tangent(const Circle &c1, const Point &p2) { +pair tangent(const Circle& c1, const Point& p2) { return crosspoint(c1, Circle(p2, sqrt(norm(c1.p - p2) - c1.r * c1.r))); } @@ -287,7 +287,7 @@ Lines tangent(Circle c1, Circle c2) { } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_B -bool is_convex(const Polygon &p) { +bool is_convex(const Polygon& p) { int n = (int)p.size(); for (int i = 0; i < n; i++) { if (ccw(p[(i + n - 1) % n], p[i], p[(i + 1) % n]) == -1) return false; @@ -296,7 +296,7 @@ bool is_convex(const Polygon &p) { } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_A -Polygon convex_hull(Polygon &p) { +Polygon convex_hull(Polygon& p) { int n = (int)p.size(), k = 0; if (n <= 2) return p; sort(p.begin(), p.end()); @@ -314,7 +314,7 @@ Polygon convex_hull(Polygon &p) { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_C enum { OUT, ON, IN }; -int contains(const Polygon &Q, const Point &p) { +int contains(const Polygon& Q, const Point& p) { bool in = false; for (int i = 0; i < Q.size(); i++) { Point a = Q[i] - p, b = Q[(i + 1) % Q.size()] - p; @@ -326,7 +326,7 @@ int contains(const Polygon &Q, const Point &p) { } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0412 -int convex_contains(const Polygon &Q, const Point &p) { +int convex_contains(const Polygon& Q, const Point& p) { int N = (int)Q.size(); Point g = (Q[0] + Q[N / 3] + Q[N * 2 / 3]) / 3.0; if (g == p) return IN; @@ -355,8 +355,8 @@ int convex_contains(const Polygon &Q, const Point &p) { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1033 // deduplication of line segments -void merge_segments(vector &segs) { - auto merge_if_able = [](Segment &s1, const Segment &s2) { +void merge_segments(vector& segs) { + auto merge_if_able = [](Segment& s1, const Segment& s2) { if (abs(cross(s1.b - s1.a, s2.b - s2.a)) > EPS) return false; if (ccw(s1.a, s2.a, s1.b) == 1 || ccw(s1.a, s2.a, s1.b) == -1) return false; if (ccw(s1.a, s1.b, s2.a) == -2 || ccw(s2.a, s2.b, s1.a) == -2) @@ -380,8 +380,8 @@ void merge_segments(vector &segs) { // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1033 // construct a graph with the vertex of the intersection of any two line // segments -vector > segment_arrangement(vector &segs, - vector &ps) { +vector > segment_arrangement(vector& segs, + vector& ps) { vector > g; int N = (int)segs.size(); for (int i = 0; i < N; i++) { @@ -418,7 +418,7 @@ vector > segment_arrangement(vector &segs, // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_C // cut with a straight line l and return a convex polygon on the left -Polygon convex_cut(const Polygon &U, Line l) { +Polygon convex_cut(const Polygon& U, Line l) { Polygon ret; for (int i = 0; i < U.size(); i++) { Point now = U[i], nxt = U[(i + 1) % U.size()]; @@ -431,7 +431,7 @@ Polygon convex_cut(const Polygon &U, Line l) { } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_A -Real area(const Polygon &p) { +Real area(const Polygon& p) { Real A = 0; for (int i = 0; i < p.size(); ++i) { A += cross(p[i], p[(i + 1) % p.size()]); @@ -440,10 +440,10 @@ Real area(const Polygon &p) { } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_H -Real area(const Polygon &p, const Circle &c) { +Real area(const Polygon& p, const Circle& c) { if (p.size() < 3) return 0.0; function cross_area = - [&](const Circle &c, const Point &a, const Point &b) { + [&](const Circle& c, const Point& a, const Point& b) { Point va = c.p - a, vb = c.p - b; Real f = cross(va, vb), ret = 0.0; if (eq(f, 0.0)) return ret; @@ -465,7 +465,7 @@ Real area(const Polygon &p, const Circle &c) { } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_B -Real convex_diameter(const Polygon &p) { +Real convex_diameter(const Polygon& p) { int N = (int)p.size(); int is = 0, js = 0; for (int i = 1; i < N; i++) { @@ -497,7 +497,7 @@ Real closest_pair(Points ps) { if (ps.size() <= 1) throw(0); sort(begin(ps), end(ps)); - auto compare_y = [&](const Point &a, const Point &b) { + auto compare_y = [&](const Point& a, const Point& b) { return imag(a) < imag(b); }; vector beet(ps.size()); diff --git a/graph/connected-components/bi-connected-components.hpp b/graph/connected-components/bi-connected-components.hpp index d272f7215..89cbb7ea5 100644 --- a/graph/connected-components/bi-connected-components.hpp +++ b/graph/connected-components/bi-connected-components.hpp @@ -19,7 +19,7 @@ struct BiConnectedComponents : LowLink { } } - explicit BiConnectedComponents(const Graph &g) : Graph(g) {} + explicit BiConnectedComponents(const Graph& g) : Graph(g) {} private: vector used; @@ -28,7 +28,7 @@ struct BiConnectedComponents : LowLink { void dfs(int idx, int par) { used[idx] = true; bool beet = false; - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (to == par && !exchange(beet, true)) continue; if (!used[to] || ord[to] < ord[idx]) { tmp.emplace_back(to); diff --git a/graph/connected-components/strongly-connected-components.hpp b/graph/connected-components/strongly-connected-components.hpp index ac7f51b4c..076c20216 100644 --- a/graph/connected-components/strongly-connected-components.hpp +++ b/graph/connected-components/strongly-connected-components.hpp @@ -14,7 +14,7 @@ struct StronglyConnectedComponents : Graph { void build() { rg = Graph(g.size()); for (size_t i = 0; i < g.size(); i++) { - for (auto &e : g[i]) { + for (auto& e : g[i]) { rg.add_directed_edge(e.to, e.from, e.cost); } } @@ -27,7 +27,7 @@ struct StronglyConnectedComponents : Graph { if (comp[i] == -1) rdfs(i, ptr), ptr++; dag = Graph(ptr); for (size_t i = 0; i < g.size(); i++) { - for (auto &e : g[i]) { + for (auto& e : g[i]) { int x = comp[e.from], y = comp[e.to]; if (x == y) continue; dag.add_directed_edge(x, y, e.cost); @@ -47,13 +47,13 @@ struct StronglyConnectedComponents : Graph { void dfs(int idx) { if (exchange(used[idx], true)) return; - for (auto &to : g[idx]) dfs(to); + for (auto& to : g[idx]) dfs(to); order.push_back(idx); } void rdfs(int idx, int cnt) { if (comp[idx] != -1) return; comp[idx] = cnt; - for (auto &to : rg.g[idx]) rdfs(to, cnt); + for (auto& to : rg.g[idx]) rdfs(to, cnt); } }; diff --git a/graph/connected-components/three-edge-connected-components.hpp b/graph/connected-components/three-edge-connected-components.hpp index b077a4e50..5470531c7 100644 --- a/graph/connected-components/three-edge-connected-components.hpp +++ b/graph/connected-components/three-edge-connected-components.hpp @@ -19,7 +19,7 @@ struct ThreeEdgeConnectedComponents : Graph { deg.assign(g.size(), 0); low.assign(g.size(), g.size()); for (size_t from = 0; from < g.size(); from++) { - for (auto &to : g[from]) { + for (auto& to : g[from]) { if ((T)from < to) bcc.add_edge(from, to); } } @@ -41,7 +41,7 @@ struct ThreeEdgeConnectedComponents : Graph { } } - int operator[](const int &k) { return uf.find(k); } + int operator[](const int& k) { return uf.find(k); } private: vector used; @@ -49,7 +49,7 @@ struct ThreeEdgeConnectedComponents : Graph { IncrementalBridgeConnectivity bcc; UnionFind uf; - void absorb(vector &path, int v, int w = -1) { + void absorb(vector& path, int v, int w = -1) { while (!path.empty()) { int x = path.back(); if (w != -1 && (in[x] > in[w] or in[w] >= out[x])) break; @@ -59,10 +59,10 @@ struct ThreeEdgeConnectedComponents : Graph { } } - void dfs(int idx, int p, vector &path, int &k) { + void dfs(int idx, int p, vector& path, int& k) { used[idx] = 1; in[idx] = low[idx] = k++; - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (idx == to || bcc.find(idx) != bcc.find(to)) continue; deg[idx]++; if (to == p) { diff --git a/graph/connected-components/two-edge-connected-components.hpp b/graph/connected-components/two-edge-connected-components.hpp index e89907e7a..67050e661 100644 --- a/graph/connected-components/two-edge-connected-components.hpp +++ b/graph/connected-components/two-edge-connected-components.hpp @@ -16,7 +16,7 @@ struct TwoEdgeConnectedComponents : LowLink { Graph tree; vector > group; - int operator[](const int &k) const { return comp[k]; } + int operator[](const int& k) const { return comp[k]; } void build() override { LowLink::build(); @@ -30,20 +30,20 @@ struct TwoEdgeConnectedComponents : LowLink { group[comp[i]].emplace_back(i); } tree = Graph(k); - for (auto &e : bridge) { + for (auto& e : bridge) { tree.add_edge(comp[e.from], comp[e.to], e.cost); } } - explicit TwoEdgeConnectedComponents(const Graph &g) : Graph(g) {} + explicit TwoEdgeConnectedComponents(const Graph& g) : Graph(g) {} private: - void dfs(int idx, int par, int &k) { + void dfs(int idx, int par, int& k) { if (par >= 0 && ord[par] >= low[idx]) comp[idx] = comp[par]; else comp[idx] = k++; - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (comp[to] == -1) dfs(to, idx, k); } } diff --git a/graph/flow/bipartite-flow.hpp b/graph/flow/bipartite-flow.hpp index c6fb35d97..d2fd5d530 100644 --- a/graph/flow/bipartite-flow.hpp +++ b/graph/flow/bipartite-flow.hpp @@ -57,7 +57,7 @@ struct BipartiteFlow { /* http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0334 */ vector > lex_max_matching() { if (!matched) max_matching(); - for (auto &vs : g) sort(begin(vs), end(vs)); + for (auto& vs : g) sort(begin(vs), end(vs)); vector > es; for (int i = 0; i < (int)n; i++) { if (match_l[i] == -1 || alive[i] == 0) { @@ -85,12 +85,12 @@ struct BipartiteFlow { } /* https://atcoder.jp/contests/utpc2013/tasks/utpc2013_11 */ - vector lex_min_vertex_cover(const vector &ord) { + vector lex_min_vertex_cover(const vector& ord) { assert(ord.size() == n + m); auto res = build_risidual_graph(); vector > r_res(n + m + 2); for (int i = 0; i < (int)(n + m + 2); i++) { - for (auto &j : res[i]) r_res[j].emplace_back(i); + for (auto& j : res[i]) r_res[j].emplace_back(i); } queue que; vector visited(n + m + 2, -1); @@ -101,7 +101,7 @@ struct BipartiteFlow { while (!que.empty()) { int idx = que.front(); que.pop(); - for (auto &to : r_res[idx]) { + for (auto& to : r_res[idx]) { if (visited[to] != -1) continue; visited[to] = 1; que.emplace(to); @@ -115,7 +115,7 @@ struct BipartiteFlow { while (!que.empty()) { int idx = que.front(); que.pop(); - for (auto &to : res[idx]) { + for (auto& to : res[idx]) { if (visited[to] != -1) continue; visited[to] = 0; que.emplace(to); @@ -125,7 +125,7 @@ struct BipartiteFlow { expand_right(n + m); expand_left(n + m + 1); vector ret; - for (auto &t : ord) { + for (auto& t : ord) { if (t < (int)n) { expand_left(t); if (visited[t] & 1) ret.emplace_back(t); @@ -190,7 +190,7 @@ struct BipartiteFlow { ris[T].emplace_back(i + n); } for (int i = 0; i < (int)n; i++) { - for (auto &j : g[i]) { + for (auto& j : g[i]) { if (match_l[i] == j) ris[j + n].emplace_back(i); else @@ -210,7 +210,7 @@ struct BipartiteFlow { while (!que.empty()) { int idx = que.front(); que.pop(); - for (auto &to : res[idx]) { + for (auto& to : res[idx]) { if (visited[to]) continue; visited[to] = true; que.emplace(to); @@ -231,7 +231,7 @@ struct BipartiteFlow { while (!que.empty()) { int a = que.front(); que.pop(); - for (auto &b : g[a]) { + for (auto& b : g[a]) { int c = match_r[b]; if (c >= 0 && dist[c] == -1) { dist[c] = dist[a] + 1; @@ -243,7 +243,7 @@ struct BipartiteFlow { bool find_min_dist_augment_path(int a) { used[a] = time_stamp; - for (auto &b : g[a]) { + for (auto& b : g[a]) { int c = match_r[b]; if (c < 0 || (used[c] != (int)time_stamp && dist[c] == dist[a] + 1 && find_min_dist_augment_path(c))) { @@ -257,7 +257,7 @@ struct BipartiteFlow { bool find_augment_path(int a) { used[a] = time_stamp; - for (auto &b : g[a]) { + for (auto& b : g[a]) { int c = match_r[b]; if (c < 0 || (alive[c] == 1 && used[c] != (int)time_stamp && find_augment_path(c))) { diff --git a/graph/flow/bipartite-matching.hpp b/graph/flow/bipartite-matching.hpp index 572b1ffd8..df118dff4 100644 --- a/graph/flow/bipartite-matching.hpp +++ b/graph/flow/bipartite-matching.hpp @@ -17,7 +17,7 @@ struct BipartiteMatching { bool augment(int idx) { used[idx] = timestamp; - for (auto &to : graph[idx]) { + for (auto& to : graph[idx]) { int to_match = match[to]; if (alive[to] == 0) continue; if (to_match == -1 || diff --git a/graph/flow/burn-bury.hpp b/graph/flow/burn-bury.hpp index 1543d8087..057280b57 100644 --- a/graph/flow/burn-bury.hpp +++ b/graph/flow/burn-bury.hpp @@ -65,7 +65,7 @@ struct BurnBury { { UF uf(n + n); for (int i = 0; i < n; i++) { - for (auto &[j, cs] : phi[i]) { + for (auto& [j, cs] : phi[i]) { T c = -cs[0] + cs[1] + cs[2] - cs[3]; if (c < 0) { uf.unite(i, j + n); @@ -77,7 +77,7 @@ struct BurnBury { } } } - for (auto &[vs, c] : zeta) { + for (auto& [vs, c] : zeta) { if (c > 0) return nullopt; if (c < 0) { for (int i = 1; i < (int)vs.size(); i++) { @@ -111,7 +111,7 @@ struct BurnBury { } { for (int i = 0; i < n; i++) { - for (auto &[j, cs] : phi[i]) { + for (auto& [j, cs] : phi[i]) { if (flip[i]) { swap(cs[0], cs[2]); swap(cs[1], cs[3]); @@ -131,7 +131,7 @@ struct BurnBury { } { for (int i = 0; i < n; i++) { - auto &cs = theta[i]; + auto& cs = theta[i]; if (flip[i]) { swap(cs[0], cs[1]); } @@ -151,7 +151,7 @@ struct BurnBury { int s = n, t = n + 1; { for (int i = 0; i < n; i++) { - auto &cs = theta[i]; + auto& cs = theta[i]; if (cs[1] > 0) { flow.add_edge(i, t, cs[1]); } @@ -160,7 +160,7 @@ struct BurnBury { } } for (int i = 0; i < n; i++) { - for (auto &[j, cs] : phi[i]) { + for (auto& [j, cs] : phi[i]) { if (cs[2] > 0) { flow.add_edge(i, j, cs[2]); } @@ -170,13 +170,13 @@ struct BurnBury { } } int u = t + 1; - for (auto &[vs, c] : zeta) { + for (auto& [vs, c] : zeta) { if (c < 0) { if ((vs[0] >= 0) ^ flip[max(~vs[0], vs[0])]) { flow.add_edge(s, u, -c); - for (auto &p : vs) flow.add_edge(u, max(p, ~p), -c); + for (auto& p : vs) flow.add_edge(u, max(p, ~p), -c); } else { - for (auto &p : vs) flow.add_edge(max(p, ~p), u, -c); + for (auto& p : vs) flow.add_edge(max(p, ~p), u, -c); flow.add_edge(u, t, -c); } alpha += c; diff --git a/graph/flow/dinic-capacity-scaling.hpp b/graph/flow/dinic-capacity-scaling.hpp index b18bd10e4..10046fb28 100644 --- a/graph/flow/dinic-capacity-scaling.hpp +++ b/graph/flow/dinic-capacity-scaling.hpp @@ -32,7 +32,7 @@ struct DinicCapacityScaling { (edge){from, 0, (int)graph[from].size() - 1, true, idx}); } - bool build_augment_path(int s, int t, const flow_t &base) { + bool build_augment_path(int s, int t, const flow_t& base) { min_cost.assign(graph.size(), -1); queue que; min_cost[s] = 0; @@ -40,7 +40,7 @@ struct DinicCapacityScaling { while (!que.empty() && min_cost[t] == -1) { int p = que.front(); que.pop(); - for (auto &e : graph[p]) { + for (auto& e : graph[p]) { if (e.cap >= base && min_cost[e.to] == -1) { min_cost[e.to] = min_cost[p] + 1; que.push(e.to); @@ -53,8 +53,8 @@ struct DinicCapacityScaling { flow_t find_augment_path(int idx, const int t, flow_t base, flow_t flow) { if (idx == t) return flow; flow_t sum = 0; - for (int &i = iter[idx]; i < (int)graph[idx].size(); i++) { - edge &e = graph[idx][i]; + for (int& i = iter[idx]; i < (int)graph[idx].size(); i++) { + edge& e = graph[idx][i]; if (e.cap >= base && min_cost[idx] < min_cost[e.to]) { flow_t d = find_augment_path(e.to, t, base, min(flow - sum, e.cap)); if (d > 0) { @@ -83,9 +83,9 @@ struct DinicCapacityScaling { void output() { for (int i = 0; i < graph.size(); i++) { - for (auto &e : graph[i]) { + for (auto& e : graph[i]) { if (e.isrev) continue; - auto &rev_e = graph[e.to][e.rev]; + auto& rev_e = graph[e.to][e.rev]; cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << e.cap + rev_e.cap << ")" << endl; } diff --git a/graph/flow/dinic.hpp b/graph/flow/dinic.hpp index 6e3bc6cbe..cf658f411 100644 --- a/graph/flow/dinic.hpp +++ b/graph/flow/dinic.hpp @@ -34,7 +34,7 @@ struct Dinic { while (!que.empty() && min_cost[t] == -1) { int p = que.front(); que.pop(); - for (auto &e : graph[p]) { + for (auto& e : graph[p]) { if (e.cap > 0 && min_cost[e.to] == -1) { min_cost[e.to] = min_cost[p] + 1; que.push(e.to); @@ -46,8 +46,8 @@ struct Dinic { flow_t find_min_dist_augment_path(int idx, const int t, flow_t flow) { if (idx == t) return flow; - for (int &i = iter[idx]; i < (int)graph[idx].size(); i++) { - edge &e = graph[idx][i]; + for (int& i = iter[idx]; i < (int)graph[idx].size(); i++) { + edge& e = graph[idx][i]; if (e.cap > 0 && min_cost[idx] < min_cost[e.to]) { flow_t d = find_min_dist_augment_path(e.to, t, min(flow, e.cap)); if (d > 0) { @@ -72,9 +72,9 @@ struct Dinic { void output() { for (int i = 0; i < graph.size(); i++) { - for (auto &e : graph[i]) { + for (auto& e : graph[i]) { if (e.isrev) continue; - auto &rev_e = graph[e.to][e.rev]; + auto& rev_e = graph[e.to][e.rev]; cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << e.cap + rev_e.cap << ")" << endl; } @@ -89,7 +89,7 @@ struct Dinic { while (not que.empty()) { int p = que.front(); que.pop(); - for (auto &e : graph[p]) { + for (auto& e : graph[p]) { if (e.cap > 0 and not used[e.to]) { used[e.to] = true; que.emplace(e.to); diff --git a/graph/flow/ford-fulkerson.hpp b/graph/flow/ford-fulkerson.hpp index 9d9961075..10ac2e8a7 100644 --- a/graph/flow/ford-fulkerson.hpp +++ b/graph/flow/ford-fulkerson.hpp @@ -33,7 +33,7 @@ struct FordFulkerson { flow_t find_augment_path(int idx, const int t, flow_t flow) { if (idx == t) return flow; used[idx] = timestamp; - for (auto &e : graph[idx]) { + for (auto& e : graph[idx]) { if (e.cap > 0 && used[e.to] != timestamp) { flow_t d = find_augment_path(e.to, t, min(flow, e.cap)); if (d > 0) { @@ -57,9 +57,9 @@ struct FordFulkerson { void output() { for (int i = 0; i < graph.size(); i++) { - for (auto &e : graph[i]) { + for (auto& e : graph[i]) { if (e.isrev) continue; - auto &rev_e = graph[e.to][e.rev]; + auto& rev_e = graph[e.to][e.rev]; cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << e.cap + rev_e.cap << ")" << endl; } diff --git a/graph/flow/global-minimum-cut-of-dynamic-star-augmented-graph.hpp b/graph/flow/global-minimum-cut-of-dynamic-star-augmented-graph.hpp index 0ad7c3c37..642c02788 100644 --- a/graph/flow/global-minimum-cut-of-dynamic-star-augmented-graph.hpp +++ b/graph/flow/global-minimum-cut-of-dynamic-star-augmented-graph.hpp @@ -16,7 +16,7 @@ struct GlobalMinimumCutofDynamicStarAugmentedGraph { GlobalMinimumCutofDynamicStarAugmentedGraph() = default; explicit GlobalMinimumCutofDynamicStarAugmentedGraph(int n, - const Edges &es) + const Edges& es) : n(n), hld(extreme_vertex_set(n, es)), cur(n), @@ -24,7 +24,7 @@ struct GlobalMinimumCutofDynamicStarAugmentedGraph { hld.build((int)hld.size() - 1); vector vs(2 * n - 1); for (int i = 0; i < 2 * n - 1; i++) { - for (auto &e : hld[i]) { + for (auto& e : hld[i]) { vs[hld.in[e.to]] = e.cost; } } diff --git a/graph/flow/hungarian.hpp b/graph/flow/hungarian.hpp index f8cd3cef1..f8f43583a 100644 --- a/graph/flow/hungarian.hpp +++ b/graph/flow/hungarian.hpp @@ -5,7 +5,7 @@ * */ template -pair > hungarian(Matrix &A) { +pair > hungarian(Matrix& A) { const T infty = numeric_limits::max(); const int N = (int)A.height(); const int M = (int)A.width(); diff --git a/graph/flow/maxflow-lower-bound.hpp b/graph/flow/maxflow-lower-bound.hpp index 3d2a2df50..46c290b92 100644 --- a/graph/flow/maxflow-lower-bound.hpp +++ b/graph/flow/maxflow-lower-bound.hpp @@ -62,10 +62,10 @@ struct MaxFlowLowerBound { void output(int M) { vector ans(M); for (int i = 0; i < flow.graph.size(); i++) { - for (auto &e : flow.graph[i]) { + for (auto& e : flow.graph[i]) { if (!e.isrev && ~e.idx) ans[e.idx] = up[e.idx] - e.cap; } } - for (auto &p : ans) cout << p << endl; + for (auto& p : ans) cout << p << endl; } }; diff --git a/graph/flow/primal-dual.hpp b/graph/flow/primal-dual.hpp index 0a46c9906..11ffd3c2b 100644 --- a/graph/flow/primal-dual.hpp +++ b/graph/flow/primal-dual.hpp @@ -44,7 +44,7 @@ struct PrimalDual { que.pop(); if (min_cost[p.second] < p.first) continue; for (int i = 0; i < (int)graph[p.second].size(); i++) { - edge &e = graph[p.second][i]; + edge& e = graph[p.second][i]; cost_t nextCost = min_cost[p.second] + e.cost + potential[p.second] - potential[e.to]; if (e.cap > 0 && min_cost[e.to] > nextCost) { @@ -63,7 +63,7 @@ struct PrimalDual { f -= addflow; ret += addflow * potential[t]; for (int v = t; v != s; v = prevv[v]) { - edge &e = graph[prevv[v]][preve[v]]; + edge& e = graph[prevv[v]][preve[v]]; e.cap -= addflow; graph[v][e.rev].cap += addflow; } @@ -73,9 +73,9 @@ struct PrimalDual { void output() { for (int i = 0; i < graph.size(); i++) { - for (auto &e : graph[i]) { + for (auto& e : graph[i]) { if (e.isrev) continue; - auto &rev_e = graph[e.to][e.rev]; + auto& rev_e = graph[e.to][e.rev]; cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << rev_e.cap + e.cap << ")" << endl; } diff --git a/graph/flow/push-relabel.hpp b/graph/flow/push-relabel.hpp index ed848c2dd..6904cff29 100644 --- a/graph/flow/push-relabel.hpp +++ b/graph/flow/push-relabel.hpp @@ -109,7 +109,7 @@ struct PushRelabel { while (!que.empty()) { int p = que.front(); que.pop(); - for (auto &e : graph[p]) { + for (auto& e : graph[p]) { if (potential[e.to] == V && graph[e.to][e.rev].cap > 0) { potential[e.to] = potential[p] + 1; que.emplace(e.to); @@ -121,7 +121,7 @@ struct PushRelabel { int init(int s, int t) { potential[s] = V + 1; bfs(t); - for (auto &e : graph[s]) { + for (auto& e : graph[s]) { if (potential[e.to] < V) { graph[e.to][e.rev].cap = e.cap; ex[s] -= e.cap; @@ -132,7 +132,7 @@ struct PushRelabel { return calc_active(t); } - bool push(int u, int t, edge &e) { + bool push(int u, int t, edge& e) { flow_t f = min(e.cap, ex[u]); int v = e.to; e.cap -= f, ex[u] -= f; @@ -142,8 +142,8 @@ struct PushRelabel { } int discharge(int u, int t) { - for (int &i = cur_edge[u]; i < (int)graph[u].size(); i++) { - auto &e = graph[u][i]; + for (int& i = cur_edge[u]; i < (int)graph[u].size(); i++) { + auto& e = graph[u][i]; if (potential[u] == potential[e.to] + 1 && e.cap > 0) { if (push(u, t, e)) return potential[u]; } @@ -171,7 +171,7 @@ struct PushRelabel { ++relabels; int prv = potential[u], cur = V; for (int i = 0; i < (int)graph[u].size(); ++i) { - const edge &e = graph[u][i]; + const edge& e = graph[u][i]; if (cur > potential[e.to] + 1 && e.cap > 0) { cur_edge[u] = i; cur = potential[e.to] + 1; diff --git a/graph/graph-template.hpp b/graph/graph-template.hpp index e95f93b63..d85f145ae 100644 --- a/graph/graph-template.hpp +++ b/graph/graph-template.hpp @@ -50,9 +50,9 @@ struct Graph { } } - inline vector > &operator[](const int &k) { return g[k]; } + inline vector >& operator[](const int& k) { return g[k]; } - inline const vector > &operator[](const int &k) const { return g[k]; } + inline const vector >& operator[](const int& k) const { return g[k]; } }; template diff --git a/graph/mst/boruvka.hpp b/graph/mst/boruvka.hpp index 7f4491f18..5f8799c1e 100644 --- a/graph/mst/boruvka.hpp +++ b/graph/mst/boruvka.hpp @@ -18,7 +18,7 @@ struct Boruvka { inline int find(int k) { return uf.find(k); } template - T build(const F &update) { + T build(const F& update) { T ret = T(); while (uf.size(0) < (int)V) { vector > v(V, make_pair(INF, -1)); diff --git a/graph/mst/directed-mst.hpp b/graph/mst/directed-mst.hpp index 27a522821..55427dad4 100644 --- a/graph/mst/directed-mst.hpp +++ b/graph/mst/directed-mst.hpp @@ -26,10 +26,10 @@ MinimumSpanningTree directed_mst(int V, int root, Edges edges) { using Node = typename Heap::Node; Heap heap; - vector ins(2 * V, heap.make_root()); + vector ins(2 * V, heap.make_root()); for (int i = 0; i < (int)edges.size(); i++) { - auto &e = edges[i]; + auto& e = edges[i]; ins[e.to] = heap.push(ins[e.to], e.cost, i); } vector st; @@ -39,7 +39,7 @@ MinimumSpanningTree directed_mst(int V, int root, Edges edges) { st.emplace_back(x); x = link[x]; } - for (auto &p : st) { + for (auto& p : st) { link[p] = x; } st.clear(); diff --git a/graph/mst/kruskal.hpp b/graph/mst/kruskal.hpp index 64b4b4a66..0e5d09442 100644 --- a/graph/mst/kruskal.hpp +++ b/graph/mst/kruskal.hpp @@ -14,13 +14,13 @@ struct MinimumSpanningTree { }; template -MinimumSpanningTree kruskal(Edges &edges, int V) { +MinimumSpanningTree kruskal(Edges& edges, int V) { sort(begin(edges), end(edges), - [](const Edge &a, const Edge &b) { return a.cost < b.cost; }); + [](const Edge& a, const Edge& b) { return a.cost < b.cost; }); UnionFind tree(V); T total = T(); Edges es; - for (auto &e : edges) { + for (auto& e : edges) { if (tree.unite(e.from, e.to)) { es.emplace_back(e); total += e.cost; diff --git a/graph/mst/prim-fibonacchi-heap.hpp b/graph/mst/prim-fibonacchi-heap.hpp index 585ad19b4..46bfd1ece 100644 --- a/graph/mst/prim-fibonacchi-heap.hpp +++ b/graph/mst/prim-fibonacchi-heap.hpp @@ -14,15 +14,15 @@ struct MinimumSpanningTree { }; template -MinimumSpanningTree prim_fibonacchi_heap(Graph &g) { +MinimumSpanningTree prim_fibonacchi_heap(Graph& g) { using Heap = FibonacchiHeap; using Node = typename Heap::Node; T total = 0; - vector *> dist(g.size()); + vector*> dist(g.size()); vector used(g.size()); Heap heap; - vector keep(g.size(), nullptr); + vector keep(g.size(), nullptr); keep[0] = heap.push(0, 0); Edges es; while (!heap.empty()) { @@ -33,7 +33,7 @@ MinimumSpanningTree prim_fibonacchi_heap(Graph &g) { used[idx] = true; total += cost; if (dist[idx]) es.emplace_back(*dist[idx]); - for (auto &e : g[idx]) { + for (auto& e : g[idx]) { if (used[e.to] || (dist[e.to] && dist[e.to]->cost <= e.cost)) continue; if (keep[e.to] == nullptr) { dist[e.to] = &e; diff --git a/graph/mst/prim.hpp b/graph/mst/prim.hpp index 962820275..4960d1a2d 100644 --- a/graph/mst/prim.hpp +++ b/graph/mst/prim.hpp @@ -13,10 +13,10 @@ struct MinimumSpanningTree { }; template -MinimumSpanningTree prim(const Graph &g) { +MinimumSpanningTree prim(const Graph& g) { T total = T(); vector used(g.size()); - vector *> dist(g.size()); + vector*> dist(g.size()); using pi = pair; priority_queue, greater<> > que; que.emplace(T(), 0); @@ -28,7 +28,7 @@ MinimumSpanningTree prim(const Graph &g) { used[p.second] = true; total += p.first; if (dist[p.second]) edges.emplace_back(*dist[p.second]); - for (auto &e : g[p.second]) { + for (auto& e : g[p.second]) { if (used[e.to] || (dist[e.to] && dist[e.to]->cost <= e.cost)) continue; que.emplace(e.cost, e.to); } diff --git a/graph/others/bipartite-graph-edge-coloring.hpp b/graph/others/bipartite-graph-edge-coloring.hpp index 6b429499b..a281dbde8 100644 --- a/graph/others/bipartite-graph-edge-coloring.hpp +++ b/graph/others/bipartite-graph-edge-coloring.hpp @@ -21,7 +21,7 @@ struct BipariteGraphEdgeColoring { }; RegularGraph g; - static UnionFind contract(valarray °, int k) { + static UnionFind contract(valarray& deg, int k) { using pi = pair; priority_queue, greater<> > que; for (int i = 0; i < (int)deg.size(); i++) { @@ -45,8 +45,8 @@ struct BipariteGraphEdgeColoring { valarray deg[2]; deg[0] = valarray(L); deg[1] = valarray(R); - for (auto &p : A) deg[0][p]++; - for (auto &p : B) deg[1][p]++; + for (auto& p : A) deg[0][p]++; + for (auto& p : B) deg[1][p]++; int k = max(deg[0].max(), deg[1].max()); @@ -95,7 +95,7 @@ struct BipariteGraphEdgeColoring { return {k, N, C, D}; } - void rec(const vector &ord, int k) { + void rec(const vector& ord, int k) { if (k == 0) { return; } else if (k == 1) { @@ -103,11 +103,11 @@ struct BipariteGraphEdgeColoring { return; } else if ((k & 1) == 0) { EulerianTrail et(g.n + g.n); - for (auto &p : ord) et.add_edge(g.A[p], g.B[p] + g.n); + for (auto& p : ord) et.add_edge(g.A[p], g.B[p] + g.n); auto paths = et.enumerate_eulerian_trail(); vector path; - for (auto &ps : paths) { - for (auto &e : ps) path.emplace_back(ord[e]); + for (auto& ps : paths) { + for (auto& e : ps) path.emplace_back(ord[e]); } vector beet[2]; for (int i = 0; i < (int)path.size(); i++) { @@ -117,11 +117,11 @@ struct BipariteGraphEdgeColoring { rec(beet[1], k / 2); } else { BipartiteFlow flow(g.n, g.n); - for (auto &i : ord) flow.add_edge(g.A[i], g.B[i]); + for (auto& i : ord) flow.add_edge(g.A[i], g.B[i]); flow.max_matching(); vector beet; ans.emplace_back(); - for (auto &i : ord) { + for (auto& i : ord) { if (flow.match_l[g.A[i]] == g.B[i]) { flow.match_l[g.A[i]] = -1; ans.back().emplace_back(i); @@ -151,7 +151,7 @@ struct BipariteGraphEdgeColoring { vector > res; for (int i = 0; i < (int)ans.size(); i++) { res.emplace_back(); - for (auto &j : ans[i]) + for (auto& j : ans[i]) if (j < (int)A.size()) res.back().emplace_back(j); } return res; diff --git a/graph/others/block-cut-tree.hpp b/graph/others/block-cut-tree.hpp index fca9f1874..debd83858 100644 --- a/graph/others/block-cut-tree.hpp +++ b/graph/others/block-cut-tree.hpp @@ -19,22 +19,22 @@ struct BlockCutTree : BiConnectedComponents { vector > group; Graph tree; - explicit BlockCutTree(const Graph &g) : Graph(g) {} + explicit BlockCutTree(const Graph& g) : Graph(g) {} - int operator[](const int &k) const { return rev[k]; } + int operator[](const int& k) const { return rev[k]; } void build() override { BiConnectedComponents::build(); rev.assign(g.size(), -1); int ptr = (int)bc.size(); - for (auto &idx : articulation) { + for (auto& idx : articulation) { rev[idx] = ptr++; } vector last(ptr, -1); tree = Graph(ptr); for (int i = 0; i < (int)bc.size(); i++) { - for (auto &e : bc[i]) { - for (auto &ver : {e.from, e.to}) { + for (auto& e : bc[i]) { + for (auto& ver : {e.from, e.to}) { if (rev[ver] >= (int)bc.size()) { if (exchange(last[rev[ver]], i) != i) { tree.add_edge(rev[ver], i, e.cost); diff --git a/graph/others/cartesian-tree.hpp b/graph/others/cartesian-tree.hpp index 7d63a5cce..7539653dc 100644 --- a/graph/others/cartesian-tree.hpp +++ b/graph/others/cartesian-tree.hpp @@ -3,7 +3,7 @@ * @brief Cartesian Tree */ template -vector cartesian_tree(const vector &v) { +vector cartesian_tree(const vector& v) { int n = (int)v.size(); vector par(n, -1); stack st; diff --git a/graph/others/chromatic-number.hpp b/graph/others/chromatic-number.hpp index 62966fc87..09dfa262f 100644 --- a/graph/others/chromatic-number.hpp +++ b/graph/others/chromatic-number.hpp @@ -6,7 +6,7 @@ * @see https://www.slideshare.net/wata_orz/ss-12131479 */ template -int chromatic_number(Matrix &g) { +int chromatic_number(Matrix& g) { int N = (int)g.size(); vector es(N); for (int i = 0; i < (int)g.size(); i++) { @@ -34,7 +34,7 @@ int chromatic_number(Matrix &g) { auto buf = hist; for (int c = 1; c < ret; c++) { int64_t sum = 0; - for (auto &[i, x] : buf) { + for (auto& [i, x] : buf) { sum += (x = int64_t(x) * i % mods[k]); } if (sum % mods[k]) ret = c; diff --git a/graph/others/cycle-detection.hpp b/graph/others/cycle-detection.hpp index 4d638583f..c8492b4a9 100644 --- a/graph/others/cycle-detection.hpp +++ b/graph/others/cycle-detection.hpp @@ -16,7 +16,7 @@ struct CycleDetection : Graph { bool dfs(int idx) { used[idx] = 1; - for (auto &e : g[idx]) { + for (auto& e : g[idx]) { if (used[e] == 0) { pre[e] = e; if (dfs(e)) return true; diff --git a/graph/others/dominator-tree.hpp b/graph/others/dominator-tree.hpp index fa703d6b9..dc063a944 100644 --- a/graph/others/dominator-tree.hpp +++ b/graph/others/dominator-tree.hpp @@ -24,7 +24,7 @@ struct DominatorTree : Graph { const int N = (int)g.size(); dfs(root); for (int i = 0; i < N; i++) { - for (auto &to : g[i]) { + for (auto& to : g[i]) { if (~semi[i]) rg.add_directed_edge(to, i); } } @@ -53,16 +53,16 @@ struct DominatorTree : Graph { idom[root] = root; } - int operator[](const int &k) const { return idom[k]; } + int operator[](const int& k) const { return idom[k]; } private: Graph rg; struct UnionFind { - const vector ; + const vector& semi; vector par, m; - explicit UnionFind(const vector &semi) + explicit UnionFind(const vector& semi) : semi(semi), par(semi.size()), m(semi.size()) { iota(begin(par), end(par), 0); iota(begin(m), end(m), 0); @@ -89,7 +89,7 @@ struct DominatorTree : Graph { void dfs(int idx) { semi[idx] = (int)ord.size(); ord.emplace_back(idx); - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (~semi[to]) continue; dfs(to); par[to] = idx; diff --git a/graph/others/enumerate-cliques.hpp b/graph/others/enumerate-cliques.hpp index 466ffc646..38c707709 100644 --- a/graph/others/enumerate-cliques.hpp +++ b/graph/others/enumerate-cliques.hpp @@ -4,7 +4,7 @@ * */ template -vector > enumerate_cliques(Matrix &g) { +vector > enumerate_cliques(Matrix& g) { int N = (int)g.size(), M = 0; vector deg(N); vector > edge(N, vector(N)); @@ -16,7 +16,7 @@ vector > enumerate_cliques(Matrix &g) { vector > cliques; - auto add_clique = [&](const vector &rem, bool last) { + auto add_clique = [&](const vector& rem, bool last) { vector neighbor((int)rem.size() - last); for (int i = 0; i < (int)neighbor.size(); i++) { for (int j = 0; j < (int)neighbor.size(); j++) { diff --git a/graph/others/enumerate-triangles.hpp b/graph/others/enumerate-triangles.hpp index 8120b0593..f1defe548 100644 --- a/graph/others/enumerate-triangles.hpp +++ b/graph/others/enumerate-triangles.hpp @@ -7,7 +7,7 @@ * */ template -vector > enumerate_triangles(const Graph &g) { +vector > enumerate_triangles(const Graph& g) { int N = (int)g.size(); using pi = pair; vector vp(N); @@ -16,7 +16,7 @@ vector > enumerate_triangles(const Graph &g) { } vector > h(N); for (int i = 0; i < N; i++) { - for (auto &j : g[i]) { + for (auto& j : g[i]) { if (vp[i] > vp[j]) { h[i].emplace_back(j); } diff --git a/graph/others/eulerian-trail.hpp b/graph/others/eulerian-trail.hpp index 5018d8e62..c7ab5e266 100644 --- a/graph/others/eulerian-trail.hpp +++ b/graph/others/eulerian-trail.hpp @@ -33,10 +33,10 @@ struct EulerianTrail { vector > enumerate_eulerian_trail() { if (directed) { - for (auto &p : deg) + for (auto& p : deg) if (p != 0) return {}; } else { - for (auto &p : deg) + for (auto& p : deg) if (p & 1) return {}; } used_edge.assign(M, 0); @@ -50,16 +50,16 @@ struct EulerianTrail { vector > enumerate_semi_eulerian_trail() { UnionFind uf(g.size()); - for (auto &p : es) uf.unite(p.first, p.second); + for (auto& p : es) uf.unite(p.first, p.second); vector > group(g.size()); for (int i = 0; i < (int)g.size(); i++) group[uf.find(i)].emplace_back(i); vector > ret; used_edge.assign(M, 0); - for (auto &vs : group) { + for (auto& vs : group) { if (vs.empty()) continue; int latte = -1, malta = -1; if (directed) { - for (auto &p : vs) { + for (auto& p : vs) { if (abs(deg[p]) > 1) { return {}; } else if (deg[p] == 1) { @@ -68,7 +68,7 @@ struct EulerianTrail { } } } else { - for (auto &p : vs) { + for (auto& p : vs) { if (deg[p] & 1) { if (latte == -1) latte = p; diff --git a/graph/others/extreme-vertex-set.hpp b/graph/others/extreme-vertex-set.hpp index 66bced14d..98afdfe5e 100644 --- a/graph/others/extreme-vertex-set.hpp +++ b/graph/others/extreme-vertex-set.hpp @@ -1,8 +1,8 @@ #include "../graph-template.hpp" template -Graph extreme_vertex_set(int n, const Edges &es) { - for (auto &e : es) { +Graph extreme_vertex_set(int n, const Edges& es) { + for (auto& e : es) { assert(0 <= e.from and e.from < n); assert(0 <= e.to and e.to < n); assert(e.from != e.to); @@ -47,7 +47,7 @@ Graph extreme_vertex_set(int n, const Edges &es) { cur[v] = -1; y = x; x = v; - for (auto &e : g[v]) { + for (auto& e : g[v]) { if (cur[e.to] != -1) { cur[e.to] -= e.cost; que.emplace(cur[e.to], e.to); diff --git a/graph/others/low-link.hpp b/graph/others/low-link.hpp index fc314e093..2c9c0526f 100644 --- a/graph/others/low-link.hpp +++ b/graph/others/low-link.hpp @@ -25,7 +25,7 @@ struct LowLink : Graph { } } - explicit LowLink(const Graph &g) : Graph(g) {} + explicit LowLink(const Graph& g) : Graph(g) {} private: vector used; @@ -36,7 +36,7 @@ struct LowLink : Graph { low[idx] = ord[idx]; bool is_articulation = false, beet = false; int cnt = 0; - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (to == par && !exchange(beet, true)) { continue; } diff --git a/graph/others/maximum-clique.hpp b/graph/others/maximum-clique.hpp index b3c54362c..c9ac38e46 100644 --- a/graph/others/maximum-clique.hpp +++ b/graph/others/maximum-clique.hpp @@ -25,12 +25,12 @@ struct MaximumClique { vector now, clique; - void dfs(vector

&rem) { + void dfs(vector

& rem) { if (clique.size() < now.size()) clique = now; sort(begin(rem), end(rem), - [](const P &a, const P &b) { return a.deg > b.deg; }); + [](const P& a, const P& b) { return a.deg > b.deg; }); int max_c = 1; - for (auto &p : rem) { + for (auto& p : rem) { p.col = 0; while ((g[p.idx] & col_buf[p.col]).any()) ++p.col; max_c = max(max_c, p.idx + 1); @@ -38,19 +38,19 @@ struct MaximumClique { } for (int i = 0; i < max_c; i++) col_buf[i].reset(); sort(begin(rem), end(rem), - [&](const P &a, const P &b) { return a.col < b.col; }); + [&](const P& a, const P& b) { return a.col < b.col; }); for (; !rem.empty(); rem.pop_back()) { - auto &p = rem.back(); + auto& p = rem.back(); if (now.size() + p.col + 1 <= clique.size()) break; vector

nrem; B bs; - for (auto &q : rem) { + for (auto& q : rem) { if (g[p.idx][q.idx]) { nrem.emplace_back(q.idx, -1, 0); bs.set(q.idx); } } - for (auto &q : nrem) { + for (auto& q : nrem) { q.deg = (bs & g[q.idx]).count(); } now.emplace_back(p.idx); diff --git a/graph/others/maximum-independent-set.hpp b/graph/others/maximum-independent-set.hpp index 3efb9d46c..485261673 100644 --- a/graph/others/maximum-independent-set.hpp +++ b/graph/others/maximum-independent-set.hpp @@ -2,7 +2,7 @@ * @brief Maximum Independent Set(最大独立集合) */ template -vector maximum_independent_set(const Matrix &g, int trial = 1000000) { +vector maximum_independent_set(const Matrix& g, int trial = 1000000) { int N = (int)g.size(); vector bit(N); assert(N <= 64); diff --git a/graph/others/minimum-steiner-tree.hpp b/graph/others/minimum-steiner-tree.hpp index f802282ce..c1c81d298 100644 --- a/graph/others/minimum-steiner-tree.hpp +++ b/graph/others/minimum-steiner-tree.hpp @@ -11,7 +11,7 @@ struct MinimumSteinerTree { MinimumSteinerTree() = default; - explicit MinimumSteinerTree(const Graph &g, const vector &terminal) + explicit MinimumSteinerTree(const Graph& g, const vector& terminal) : g(g), terminal(terminal), dp(1 << terminal.size(), vector(g.size(), infty)), @@ -46,7 +46,7 @@ struct MinimumSteinerTree { que.pop(); if (dp[i][v] < now) continue; for (int j = 0; j < (int)g[v].size(); j++) { - const auto &e = g[v][j]; + const auto& e = g[v][j]; if (now + e.cost < dp[i][e.to]) { dp[i][e.to] = now + e.cost; pre[i][e.to] = {v, j}; @@ -81,7 +81,7 @@ struct MinimumSteinerTree { } private: - const Graph &g; - const vector &terminal; + const Graph& g; + const vector& terminal; vector > pre; }; diff --git a/graph/others/namori-graph.hpp b/graph/others/namori-graph.hpp index 17d9abbb4..07f492ec2 100644 --- a/graph/others/namori-graph.hpp +++ b/graph/others/namori-graph.hpp @@ -19,7 +19,7 @@ struct NamoriGraph : Graph { int tree_id, id; }; - Info operator[](const int &k) const { return (Info){mark_id[k], id[k]}; } + Info operator[](const int& k) const { return (Info){mark_id[k], id[k]}; } int inv(int tree_id, int k) { return iv[tree_id][k]; } @@ -37,7 +37,7 @@ struct NamoriGraph : Graph { while (not que.empty()) { int idx = que.front(); que.pop(); - for (auto &e : g[idx]) { + for (auto& e : g[idx]) { if (used[e.to]) { continue; } @@ -49,8 +49,8 @@ struct NamoriGraph : Graph { } } int mx = 0; - for (auto &edges : g) { - for (auto &e : edges) mx = max(mx, e.idx); + for (auto& edges : g) { + for (auto& e : edges) mx = max(mx, e.idx); } vector edge_used(mx + 1); vector loop; @@ -59,7 +59,7 @@ struct NamoriGraph : Graph { for (bool update = true; update;) { update = false; loop.emplace_back(v); - for (auto &e : g[v]) { + for (auto& e : g[v]) { if (used[e.to] or edge_used[e.idx]) { continue; } @@ -84,13 +84,13 @@ struct NamoriGraph : Graph { iv.emplace_back(); id[loop[i]] = sz++; iv.back().emplace_back(loop[i]); - for (auto &e : g[loop[i]]) { + for (auto& e : g[loop[i]]) { if (e.to != pre and e.to != nxt) { mark_dfs(e.to, loop[i], i, sz); } } Graph tree(sz); - for (auto &e : g[loop[i]]) { + for (auto& e : g[loop[i]]) { if (e.to != pre and e.to != nxt) { tree.g[id[loop[i]]].emplace_back(id[loop[i]], id[e.to], e.cost, e.idx); @@ -106,19 +106,19 @@ struct NamoriGraph : Graph { vector > iv; vector mark_id, id; - void mark_dfs(int idx, int par, int k, int &l) { + void mark_dfs(int idx, int par, int k, int& l) { mark_id[idx] = k; id[idx] = l++; iv.back().emplace_back(idx); - for (auto &e : g[idx]) { + for (auto& e : g[idx]) { if (e.to != par) { mark_dfs(e.to, idx, k, l); } } } - void build_dfs(int idx, int par, Graph &tree) { - for (auto &e : g[idx]) { + void build_dfs(int idx, int par, Graph& tree) { + for (auto& e : g[idx]) { if (e.to != par) { tree.g[id[idx]].emplace_back(id[idx], id[e.to], e.cost, e.idx); tree.g[id[e.to]].emplace_back(id[e.to], id[idx], e.cost, e.idx); diff --git a/graph/others/offline-dag-reachability.hpp b/graph/others/offline-dag-reachability.hpp index 410a9208b..bdabd1d52 100644 --- a/graph/others/offline-dag-reachability.hpp +++ b/graph/others/offline-dag-reachability.hpp @@ -9,8 +9,8 @@ */ template -vector offline_dag_reachability(const Graph &g, - vector > &qs) { +vector offline_dag_reachability(const Graph& g, + vector >& qs) { const int N = (int)g.size(); const int Q = (int)qs.size(); auto ord = topological_sort(g); @@ -21,8 +21,8 @@ vector offline_dag_reachability(const Graph &g, for (int k = l; k < r; k++) { dp[qs[k].first] |= int64_t(1) << (k - l); } - for (auto &idx : ord) { - for (auto &to : g[idx]) dp[to] |= dp[idx]; + for (auto& idx : ord) { + for (auto& to : g[idx]) dp[to] |= dp[idx]; } for (int k = l; k < r; k++) { ans[k] = (dp[qs[k].second] >> (k - l)) & 1; diff --git a/graph/others/topological-sort.hpp b/graph/others/topological-sort.hpp index 7d451650e..9d6940cd5 100644 --- a/graph/others/topological-sort.hpp +++ b/graph/others/topological-sort.hpp @@ -7,11 +7,11 @@ * */ template -vector topological_sort(const Graph &g) { +vector topological_sort(const Graph& g) { const int N = (int)g.size(); vector deg(N); for (int i = 0; i < N; i++) { - for (auto &to : g[i]) ++deg[to]; + for (auto& to : g[i]) ++deg[to]; } stack st; for (int i = 0; i < N; i++) { @@ -22,7 +22,7 @@ vector topological_sort(const Graph &g) { auto p = st.top(); st.pop(); ord.emplace_back(p); - for (auto &to : g[p]) { + for (auto& to : g[p]) { if (--deg[to] == 0) st.emplace(to); } } diff --git a/graph/others/tree-decomposition-width-2.hpp b/graph/others/tree-decomposition-width-2.hpp index 303f0cd51..49c52de04 100644 --- a/graph/others/tree-decomposition-width-2.hpp +++ b/graph/others/tree-decomposition-width-2.hpp @@ -33,7 +33,7 @@ struct TreeDecompositionWidth2 { vector > exists(N); for (int i = 0; i < N; i++) { - for (auto &j : g[i]) { + for (auto& j : g[i]) { if (i < j) exists[i].emplace(j); } } @@ -48,7 +48,7 @@ struct TreeDecompositionWidth2 { DecompNode r; r.bag.emplace_back(idx); int u = -1, v = -1; - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (used[to] == -1) { (u == -1 ? u : v) = to; r.bag.emplace_back(to); @@ -73,7 +73,7 @@ struct TreeDecompositionWidth2 { } } - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (deg[to] <= 2) que.emplace(to); } @@ -90,8 +90,8 @@ struct TreeDecompositionWidth2 { } }; -void to_nice(vector &g, int root = 0) { - for (auto &p : g) { +void to_nice(vector& g, int root = 0) { + for (auto& p : g) { sort(p.bag.begin(), p.bag.end()); } @@ -116,7 +116,7 @@ void to_nice(vector &g, int root = 0) { } if (g[idx].child.size() == 2) { - for (auto &ch : g[idx].child) { + for (auto& ch : g[idx].child) { if (g[ch].bag != g[idx].bag) { DecompNode r; r.child = {ch}; @@ -129,7 +129,7 @@ void to_nice(vector &g, int root = 0) { // introduce / forget if (g[idx].child.size() == 1) { - int &ch = g[idx].child[0]; + int& ch = g[idx].child[0]; vector latte, malta; set_difference(g[idx].bag.begin(), g[idx].bag.end(), g[ch].bag.begin(), @@ -161,7 +161,7 @@ void to_nice(vector &g, int root = 0) { } } - for (auto &ch : g[idx].child) { + for (auto& ch : g[idx].child) { st.emplace(ch); } } diff --git a/graph/shortest-path/bellman-ford.hpp b/graph/shortest-path/bellman-ford.hpp index c824afd59..14830607e 100644 --- a/graph/shortest-path/bellman-ford.hpp +++ b/graph/shortest-path/bellman-ford.hpp @@ -1,20 +1,20 @@ #include "../graph-template.hpp" template -vector bellman_ford(const Edges &edges, int n, int s) { +vector bellman_ford(const Edges& edges, int n, int s) { const auto INF = numeric_limits::max(); const auto M_INF = numeric_limits::min(); vector dist(n, INF); dist[s] = 0; for (int i = 0; i < n - 1; i++) { - for (auto &e : edges) { + for (auto& e : edges) { if (dist[e.from] == INF) continue; dist[e.to] = min(dist[e.to], dist[e.from] + e.cost); } } vector negative(n); for (int i = 0; i < n; i++) { - for (auto &e : edges) { + for (auto& e : edges) { if (dist[e.from] == INF) continue; if (dist[e.from] + e.cost < dist[e.to]) { dist[e.to] = dist[e.from] + e.cost; diff --git a/graph/shortest-path/bfs.hpp b/graph/shortest-path/bfs.hpp index fbd9e4bf0..4ee888de1 100644 --- a/graph/shortest-path/bfs.hpp +++ b/graph/shortest-path/bfs.hpp @@ -6,10 +6,10 @@ * @brief BFS(幅優先探索) */ template -vector bfs(const Graph &g, int s) { +vector bfs(const Graph& g, int s) { T max_cost = 0, beet = 0; - for (auto &es : g.g) { - for (auto &e : es) max_cost = max(max_cost, e.cost); + for (auto& es : g.g) { + for (auto& e : es) max_cost = max(max_cost, e.cost); } ++max_cost; const auto INF = numeric_limits::max(); @@ -18,12 +18,12 @@ vector bfs(const Graph &g, int s) { dist[s] = 0; ques[0].emplace(s); for (T cost = 0; cost <= beet; cost++) { - auto &que = ques[cost % max_cost]; + auto& que = ques[cost % max_cost]; while (!que.empty()) { int idx = que.front(); que.pop(); if (dist[idx] < cost) continue; - for (auto &e : g[idx]) { + for (auto& e : g[idx]) { auto next_cost = cost + e.cost; if (dist[e.to] <= next_cost) continue; ; diff --git a/graph/shortest-path/complement-shotest-path.hpp b/graph/shortest-path/complement-shotest-path.hpp index 9696f69bf..2f110fd7f 100644 --- a/graph/shortest-path/complement-shotest-path.hpp +++ b/graph/shortest-path/complement-shotest-path.hpp @@ -13,9 +13,9 @@ struct ComplementShortestPath : Graph { vector > dists; void build() { - for (auto &es : g) { + for (auto& es : g) { sort(begin(es), end(es), - [&](const Edge &a, const Edge &b) { return a.to < b.to; }); + [&](const Edge& a, const Edge& b) { return a.to < b.to; }); } const int N = (int)g.size(); dists.resize(N); @@ -64,7 +64,7 @@ struct ComplementShortestPath : Graph { que.pop(); int ptr = 0; vector nxt_visited; - for (auto &to : not_visited) { + for (auto& to : not_visited) { while (ptr < (int)g[idx].size() and g[idx][ptr].to < to) { ++ptr; } diff --git a/graph/shortest-path/dijkstra-fibonacchi-heap.hpp b/graph/shortest-path/dijkstra-fibonacchi-heap.hpp index 2c678fdab..69199b5e4 100644 --- a/graph/shortest-path/dijkstra-fibonacchi-heap.hpp +++ b/graph/shortest-path/dijkstra-fibonacchi-heap.hpp @@ -8,13 +8,13 @@ * */ template -vector dijkstra_fibonacchi_heap(Graph &g, int s) { +vector dijkstra_fibonacchi_heap(Graph& g, int s) { const auto INF = numeric_limits::max(); using Heap = FibonacchiHeap; using Node = typename Heap::Node; Heap heap; - vector keep(g.size(), nullptr); + vector keep(g.size(), nullptr); vector dist; dist.assign(g.size(), INF); dist[s] = 0; @@ -25,7 +25,7 @@ vector dijkstra_fibonacchi_heap(Graph &g, int s) { int idx; tie(cost, idx) = heap.pop(); if (dist[idx] < cost) continue; - for (auto &e : g[idx]) { + for (auto& e : g[idx]) { auto next_cost = cost + e.cost; if (dist[e.to] <= next_cost) continue; if (keep[e.to] == nullptr) { diff --git a/graph/shortest-path/dijkstra-radix-heap.hpp b/graph/shortest-path/dijkstra-radix-heap.hpp index 8fa9c827e..395ad1fd7 100644 --- a/graph/shortest-path/dijkstra-radix-heap.hpp +++ b/graph/shortest-path/dijkstra-radix-heap.hpp @@ -6,7 +6,7 @@ * @brief Dijkstra-Radix-Heap(単一始点最短路) */ template -vector dijkstra_radix_heap(Graph &g, int s) { +vector dijkstra_radix_heap(Graph& g, int s) { const auto INF = numeric_limits::max(); vector dist(g.size(), INF); @@ -18,7 +18,7 @@ vector dijkstra_radix_heap(Graph &g, int s) { int idx; tie(cost, idx) = heap.pop(); if (dist[idx] < cost) continue; - for (auto &e : g.g[idx]) { + for (auto& e : g.g[idx]) { auto next_cost = cost + e.cost; if (dist[e.to] <= next_cost) continue; dist[e.to] = next_cost; diff --git a/graph/shortest-path/dijkstra.hpp b/graph/shortest-path/dijkstra.hpp index 27f1fcbf1..c35c08906 100644 --- a/graph/shortest-path/dijkstra.hpp +++ b/graph/shortest-path/dijkstra.hpp @@ -13,7 +13,7 @@ struct ShortestPath { }; template -ShortestPath dijkstra(const Graph &g, int s) { +ShortestPath dijkstra(const Graph& g, int s) { const auto INF = numeric_limits::max(); vector dist(g.size(), INF); vector from(g.size(), -1), id(g.size(), -1); @@ -27,7 +27,7 @@ ShortestPath dijkstra(const Graph &g, int s) { tie(cost, idx) = que.top(); que.pop(); if (dist[idx] < cost) continue; - for (auto &e : g[idx]) { + for (auto& e : g[idx]) { auto next_cost = cost + e.cost; if (dist[e.to] <= next_cost) continue; dist[e.to] = next_cost; diff --git a/graph/shortest-path/grid-bfs.hpp b/graph/shortest-path/grid-bfs.hpp index 895f12bca..8d7338b63 100644 --- a/graph/shortest-path/grid-bfs.hpp +++ b/graph/shortest-path/grid-bfs.hpp @@ -1,5 +1,5 @@ -vector > grid_bfs(vector &s, char start, - const string &wall = "#") { +vector > grid_bfs(vector& s, char start, + const string& wall = "#") { const int vx[] = {0, 1, 0, -1}, vy[] = {1, 0, -1, 0}; vector > min_cost(s.size(), vector(s[0].size(), -1)); queue > que; diff --git a/graph/shortest-path/k-shortest-path.hpp b/graph/shortest-path/k-shortest-path.hpp index 4e67576b1..016abf71a 100644 --- a/graph/shortest-path/k-shortest-path.hpp +++ b/graph/shortest-path/k-shortest-path.hpp @@ -8,7 +8,7 @@ * @see https://qiita.com/nariaki3551/items/821dc6ffdc552d3d5f22 */ template -vector > > k_shortest_path(const Graph &g, int s, int t, +vector > > k_shortest_path(const Graph& g, int s, int t, int k) { assert(s != t); int N = (int)g.size(); @@ -17,7 +17,7 @@ vector > > k_shortest_path(const Graph &g, int s, int t, vector latte(M), malta(M); vector cost(M); for (int i = 0; i < N; i++) { - for (auto &e : g[i]) { + for (auto& e : g[i]) { latte[e.idx] = i; malta[e.idx] = e.to; cost[e.idx] = e.cost; @@ -26,7 +26,7 @@ vector > > k_shortest_path(const Graph &g, int s, int t, const auto INF = numeric_limits::max(); vector dame(M, -1); int timestamp = 0; - auto shortest_path = [&](vector &dist, vector &from, vector &id, + auto shortest_path = [&](vector& dist, vector& from, vector& id, int st) { using Pi = pair; priority_queue, greater<> > que; @@ -38,7 +38,7 @@ vector > > k_shortest_path(const Graph &g, int s, int t, que.pop(); if (dist[idx] < cost) continue; if (idx == t) return; - for (auto &e : g[idx]) { + for (auto& e : g[idx]) { auto next_cost = cost + e.cost; if (dist[e.to] <= next_cost) continue; if (dame[e.idx] == timestamp) continue; @@ -49,7 +49,7 @@ vector > > k_shortest_path(const Graph &g, int s, int t, } } }; - auto restore = [](const vector &es, const vector &vs, int from, + auto restore = [](const vector& es, const vector& vs, int from, int to) { vector tap; while (to != from) { @@ -77,10 +77,10 @@ vector > > k_shortest_path(const Graph &g, int s, int t, dist[s] = 0; vector candidate(A.size()); iota(begin(candidate), end(candidate), 0); - auto &last_path = A.back().second; + auto& last_path = A.back().second; int cur = s; for (int j = 0; j < last_path.size(); j++) { - for (auto &k : candidate) { + for (auto& k : candidate) { if (j < A[k].second.size()) dame[A[k].second[j]] = timestamp; } vector dist2{dist}; @@ -90,7 +90,7 @@ vector > > k_shortest_path(const Graph &g, int s, int t, if (dist2[t] != INF) { auto path = restore(id2, from2, s, t); bool ok = true; - for (auto &p : candidate) { + for (auto& p : candidate) { if (path == A[p].second) { ok = false; break; @@ -99,7 +99,7 @@ vector > > k_shortest_path(const Graph &g, int s, int t, if (ok) B.emplace(dist2[t], path); } vector accept; - for (auto &k : candidate) { + for (auto& k : candidate) { if (j < A[k].second.size() && A[k].second[j] == last_path[j]) { accept.emplace_back(k); } diff --git a/graph/shortest-path/k-shortest-walk.hpp b/graph/shortest-path/k-shortest-walk.hpp index 1626e6364..5fd43c1d0 100644 --- a/graph/shortest-path/k-shortest-walk.hpp +++ b/graph/shortest-path/k-shortest-walk.hpp @@ -8,15 +8,15 @@ * @see https://qiita.com/hotman78/items/42534a01c4bd05ed5e1e */ template -vector k_shortest_walk(const Graph &g, int s, int t, int k) { +vector k_shortest_walk(const Graph& g, int s, int t, int k) { int N = (int)g.size(); Graph rg(N); for (int i = 0; i < N; i++) { - for (auto &e : g[i]) rg.add_directed_edge(e.to, i, e.cost); + for (auto& e : g[i]) rg.add_directed_edge(e.to, i, e.cost); } auto dist = dijkstra(rg, t); if (dist.from[s] == -1) return {}; - auto &p = dist.dist; + auto& p = dist.dist; vector > ch(N); for (int i = 0; i < N; i++) { if (dist.from[i] >= 0) ch[dist.from[i]].emplace_back(i); @@ -24,7 +24,7 @@ vector k_shortest_walk(const Graph &g, int s, int t, int k) { using PHeap = PersistentLeftistHeap; using Node = typename PHeap::Node; PHeap heap; - vector h(N, heap.make_root()); + vector h(N, heap.make_root()); { queue que; que.emplace(t); @@ -35,7 +35,7 @@ vector k_shortest_walk(const Graph &g, int s, int t, int k) { h[idx] = heap.meld(h[idx], h[dist.from[idx]]); } bool used = true; - for (auto &e : g[idx]) { + for (auto& e : g[idx]) { if (e.to != t && dist.from[e.to] == -1) continue; if (used && dist.from[idx] == e.to && p[e.to] + e.cost == p[idx]) { used = false; @@ -43,19 +43,19 @@ vector k_shortest_walk(const Graph &g, int s, int t, int k) { } h[idx] = heap.push(h[idx], e.cost - p[idx] + p[e.to], e.to); } - for (auto &to : ch[idx]) que.emplace(to); + for (auto& to : ch[idx]) que.emplace(to); } } - using pi = pair; - auto comp = [](const pi &x, const pi &y) { return x.first > y.first; }; + using pi = pair; + auto comp = [](const pi& x, const pi& y) { return x.first > y.first; }; priority_queue, decltype(comp)> que(comp); - Node *root = heap.make_root(); + Node* root = heap.make_root(); root = heap.push(root, p[s], s); que.emplace(p[s], root); vector ans; while (!que.empty()) { T cost; - Node *cur; + Node* cur; tie(cost, cur) = que.top(); que.pop(); ans.emplace_back(cost); diff --git a/graph/shortest-path/shortest-nonzero-path.hpp b/graph/shortest-path/shortest-nonzero-path.hpp index 400c56618..7126861b4 100644 --- a/graph/shortest-path/shortest-nonzero-path.hpp +++ b/graph/shortest-path/shortest-nonzero-path.hpp @@ -22,14 +22,14 @@ struct ShortestNonzeroPath { void unite_uf(int r, int c) { uf[c] = r; } public: - explicit ShortestNonzeroPath(int n, const F &f) : g(n), f(f) {} + explicit ShortestNonzeroPath(int n, const F& f) : g(n), f(f) {} - void add_undirected_edge(int u, int v, const T &cost, const S &label) { + void add_undirected_edge(int u, int v, const T& cost, const S& label) { add_directed_edge(u, v, cost, label); add_directed_edge(v, u, cost, label); } - void add_directed_edge(int u, int v, const T &cost, const S &label) { + void add_directed_edge(int u, int v, const T& cost, const S& label) { g[u].emplace_back((edge){v, cost, label}); } @@ -80,7 +80,7 @@ struct ShortestNonzeroPath { for (int u = 0; u < n; u++) { if (sp.dist[u] != INF) { for (int i = 0; i < (int)g[u].size(); i++) { - auto &e = g[u][i]; + auto& e = g[u][i]; if (u < e.to and f(sp.label[u], e.label) != sp.label[e.to]) { que.emplace(sp.dist[u] + sp.dist[e.to] + e.cost, u, i); } @@ -105,11 +105,11 @@ struct ShortestNonzeroPath { v = find_uf(sp.parent[v]); } } - for (auto &x : bs) { + for (auto& x : bs) { unite_uf(u, x); dist[x] = cost - sp.dist[x]; for (int j = 0; j < (int)g[x].size(); j++) { - auto &e = g[x][j]; + auto& e = g[x][j]; if (f(sp.label[x], e.label) == sp.label[e.to]) { que.emplace(dist[x] + sp.dist[e.to] + e.cost, x, j); } @@ -127,6 +127,6 @@ struct ShortestNonzeroPath { }; template -ShortestNonzeroPath get_shortest_nonzero_path(int N, const F &f) { +ShortestNonzeroPath get_shortest_nonzero_path(int N, const F& f) { return ShortestNonzeroPath{N, f}; } diff --git a/graph/shortest-path/shortest-path-faster-algorithm.hpp b/graph/shortest-path/shortest-path-faster-algorithm.hpp index 8232b6e78..60aebfd10 100644 --- a/graph/shortest-path/shortest-path-faster-algorithm.hpp +++ b/graph/shortest-path/shortest-path-faster-algorithm.hpp @@ -6,7 +6,7 @@ * @brief Shortest-Path-Faster-Algorithm(単一始点最短路) */ template -vector shortest_path_faster_algorithm(const Graph &g, int s) { +vector shortest_path_faster_algorithm(const Graph& g, int s) { const auto INF = numeric_limits::max(); vector dist(g.size(), INF); vector pending(g.size(), 0), times(g.size(), 0); @@ -21,7 +21,7 @@ vector shortest_path_faster_algorithm(const Graph &g, int s) { int p = que.front(); que.pop(); pending[p] = false; - for (auto &e : g[p]) { + for (auto& e : g[p]) { T next_cost = dist[p] + e.cost; if (next_cost >= dist[e.to]) continue; dist[e.to] = next_cost; diff --git a/graph/shortest-path/warshall-floyd.hpp b/graph/shortest-path/warshall-floyd.hpp index 4c63e74f9..4ccc9d63a 100644 --- a/graph/shortest-path/warshall-floyd.hpp +++ b/graph/shortest-path/warshall-floyd.hpp @@ -2,7 +2,7 @@ * @brief Warshall Floyd(全点対間最短路) */ template -void warshall_floyd(Matrix &g, T INF) { +void warshall_floyd(Matrix& g, T INF) { for (size_t k = 0; k < g.size(); k++) { for (size_t i = 0; i < g.size(); i++) { for (size_t j = 0; j < g.size(); j++) { diff --git a/graph/tree/centroid-decomposition.hpp b/graph/tree/centroid-decomposition.hpp index 59ff3b140..e6737e642 100644 --- a/graph/tree/centroid-decomposition.hpp +++ b/graph/tree/centroid-decomposition.hpp @@ -19,7 +19,7 @@ struct CentroidDecomposition : Graph { return build_dfs(0); } - explicit CentroidDecomposition(const Graph &g) : Graph(g) {} + explicit CentroidDecomposition(const Graph& g) : Graph(g) {} private: vector sub; @@ -27,7 +27,7 @@ struct CentroidDecomposition : Graph { inline int build_dfs(int idx, int par) { sub[idx] = 1; - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (to == par || v[to]) continue; sub[idx] += build_dfs(to, idx); } @@ -35,7 +35,7 @@ struct CentroidDecomposition : Graph { } inline int search_centroid(int idx, int par, const int mid) { - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (to == par || v[to]) continue; if (sub[to] > mid) return search_centroid(to, idx, mid); } @@ -45,7 +45,7 @@ struct CentroidDecomposition : Graph { inline int build_dfs(int idx) { int centroid = search_centroid(idx, -1, build_dfs(idx, -1) / 2); v[centroid] = true; - for (auto &to : g[centroid]) { + for (auto& to : g[centroid]) { if (!v[to]) tree.add_directed_edge(centroid, build_dfs(to)); } v[centroid] = false; diff --git a/graph/tree/centroid.hpp b/graph/tree/centroid.hpp index f6673cb14..2dd47da23 100644 --- a/graph/tree/centroid.hpp +++ b/graph/tree/centroid.hpp @@ -7,7 +7,7 @@ * */ template -vector centroid(const Graph &g) { +vector centroid(const Graph& g) { const int N = (int)g.size(); stack > st; @@ -17,10 +17,10 @@ vector centroid(const Graph &g) { auto p = st.top(); if (sz[p.first] == 0) { sz[p.first] = 1; - for (auto &to : g[p.first]) + for (auto& to : g[p.first]) if (to != p.second) st.emplace(to, p.first); } else { - for (auto &to : g[p.first]) + for (auto& to : g[p.first]) if (to != p.second) sz[p.first] += sz[to]; par[p.first] = p.second; st.pop(); @@ -31,7 +31,7 @@ vector centroid(const Graph &g) { int size = N; for (int i = 0; i < N; i++) { int val = N - sz[i]; - for (auto &to : g[i]) + for (auto& to : g[i]) if (to != par[i]) val = max(val, sz[to]); if (val < size) size = val, ret.clear(); if (val == size) ret.emplace_back(i); diff --git a/graph/tree/convert-rooted-tree.hpp b/graph/tree/convert-rooted-tree.hpp index c94a3a086..e33de5799 100644 --- a/graph/tree/convert-rooted-tree.hpp +++ b/graph/tree/convert-rooted-tree.hpp @@ -6,7 +6,7 @@ * @brief Convert-Rooted-Tree(根付き木に変換) */ template -Graph convert_rooted_tree(const Graph &g, int r = 0) { +Graph convert_rooted_tree(const Graph& g, int r = 0) { int N = (int)g.size(); Graph rg(N); vector v(N); @@ -16,7 +16,7 @@ Graph convert_rooted_tree(const Graph &g, int r = 0) { while (!que.empty()) { auto p = que.front(); que.pop(); - for (auto &to : g[p]) { + for (auto& to : g[p]) { if (v[to] == 0) { v[to] = 1; que.emplace(to); diff --git a/graph/tree/disjoint-set-union-on-tree.hpp b/graph/tree/disjoint-set-union-on-tree.hpp index 6776a44e7..a7ea9632e 100644 --- a/graph/tree/disjoint-set-union-on-tree.hpp +++ b/graph/tree/disjoint-set-union-on-tree.hpp @@ -24,7 +24,7 @@ struct DisjointSetUnionOnTree : Graph { int build_subtree(int idx) { in[idx] = ord.size(); ord.emplace_back(idx); - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { int sub = build_subtree(to); sz[idx] += sub; if (heavy[idx] == -1 || sz[heavy[idx]] < sub) { @@ -36,14 +36,14 @@ struct DisjointSetUnionOnTree : Graph { } void dfs(int idx, bool keep) { - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (heavy[idx] == to) continue; dfs(to, false); } if (heavy[idx] != -1) { dfs(heavy[idx], true); } - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (heavy[idx] == to) continue; for (int p = in[to]; p < out[to]; p++) { expand(ord[p]); diff --git a/graph/tree/doubling-lowest-common-ancestor.hpp b/graph/tree/doubling-lowest-common-ancestor.hpp index d10b8690d..a3e4163ae 100644 --- a/graph/tree/doubling-lowest-common-ancestor.hpp +++ b/graph/tree/doubling-lowest-common-ancestor.hpp @@ -18,7 +18,7 @@ struct DoublingLowestCommonAncestor : Graph { explicit DoublingLowestCommonAncestor(int n) : Graph(n), LOG(32 - __builtin_clz(g.size())) {} - explicit DoublingLowestCommonAncestor(const Graph &g) + explicit DoublingLowestCommonAncestor(const Graph& g) : LOG(32 - __builtin_clz(g.size())), Graph(g) {} void build(int root = 0) { @@ -63,7 +63,7 @@ struct DoublingLowestCommonAncestor : Graph { void dfs(int idx, int par, int d) { table[0][idx] = par; dep[idx] = d; - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (to != par) { sum[to] = sum[idx] + to.cost; dfs(to, idx, d + 1); diff --git a/graph/tree/heavy-light-decomposition.hpp b/graph/tree/heavy-light-decomposition.hpp index 461e2b7c3..50aa386bc 100644 --- a/graph/tree/heavy-light-decomposition.hpp +++ b/graph/tree/heavy-light-decomposition.hpp @@ -47,7 +47,7 @@ struct HeavyLightDecomposition : Graph { int dist(int u, int v) const { return dep[u] + dep[v] - 2 * dep[lca(u, v)]; } template - E query(int u, int v, const E &ti, const Q &q, const F &f, const S &s, + E query(int u, int v, const E& ti, const Q& q, const F& f, const S& s, bool edge = false) { E l = ti, r = ti; for (;; v = par[head[v]]) { @@ -59,13 +59,13 @@ struct HeavyLightDecomposition : Graph { } template - E query(int u, int v, const E &ti, const Q &q, const F &f, + E query(int u, int v, const E& ti, const Q& q, const F& f, bool edge = false) { return query(u, v, ti, q, f, f, edge); } template - void add(int u, int v, const Q &q, bool edge = false) { + void add(int u, int v, const Q& q, bool edge = false) { for (;; v = par[head[v]]) { if (in[u] > in[v]) swap(u, v); if (head[u] == head[v]) break; @@ -75,7 +75,7 @@ struct HeavyLightDecomposition : Graph { } /* {parent, child} */ - vector > compress(vector &remark) { + vector > compress(vector& remark) { auto cmp = [&](int a, int b) { return in[a] < in[b]; }; sort(begin(remark), end(remark), cmp); remark.erase(unique(begin(remark), end(remark)), end(remark)); @@ -86,7 +86,7 @@ struct HeavyLightDecomposition : Graph { remark.erase(unique(begin(remark), end(remark)), end(remark)); vector > es; stack st; - for (auto &k : remark) { + for (auto& k : remark) { while (!st.empty() && out[st.top()] <= in[k]) st.pop(); if (!st.empty()) es.emplace_back(st.top(), k); st.emplace(k); @@ -94,7 +94,7 @@ struct HeavyLightDecomposition : Graph { return es; } - explicit HeavyLightDecomposition(const Graph &g) : Graph(g) {} + explicit HeavyLightDecomposition(const Graph& g) : Graph(g) {} private: void dfs_sz(int idx, int p, int d) { @@ -102,7 +102,7 @@ struct HeavyLightDecomposition : Graph { par[idx] = p; sz[idx] = 1; if (g[idx].size() && g[idx][0] == p) swap(g[idx][0], g[idx].back()); - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (to == p) continue; dfs_sz(to, idx, d + 1); sz[idx] += sz[to]; @@ -110,10 +110,10 @@ struct HeavyLightDecomposition : Graph { } } - void dfs_hld(int idx, int p, int ×) { + void dfs_hld(int idx, int p, int& times) { in[idx] = times++; rev[in[idx]] = idx; - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (to == p) continue; head[to] = (g[idx][0] == to ? head[idx] : to); dfs_hld(to, idx, times); diff --git a/graph/tree/offline-lca.hpp b/graph/tree/offline-lca.hpp index b7ca98982..57f813077 100644 --- a/graph/tree/offline-lca.hpp +++ b/graph/tree/offline-lca.hpp @@ -5,14 +5,14 @@ * @brief Offline LCA(オフライン最小共通祖先) **/ template -vector offline_lca(const Graph &g, vector > &qs, +vector offline_lca(const Graph& g, vector >& qs, int root = 0) { int n = (int)g.size(); UnionFind uf(n); vector st(n), mark(n), ptr(n), ans(qs.size(), -1); int top = 0; st[top] = root; - for (auto &[l, r] : qs) mark[l]++, mark[r]++; + for (auto& [l, r] : qs) mark[l]++, mark[r]++; vector > > q(n); for (int i = 0; i < n; i++) { q[i].reserve(mark[i]); @@ -42,7 +42,7 @@ vector offline_lca(const Graph &g, vector > &qs, mark[uf.find(u)] = u; } if (not run(u)) { - for (auto &[v, i] : q[u]) { + for (auto& [v, i] : q[u]) { if (~mark[v] and ans[i] == -1) { ans[i] = mark[uf.find(v)]; } diff --git a/graph/tree/pmormq-lowest-common-ancestor.hpp b/graph/tree/pmormq-lowest-common-ancestor.hpp index b485b96be..bc702aadc 100644 --- a/graph/tree/pmormq-lowest-common-ancestor.hpp +++ b/graph/tree/pmormq-lowest-common-ancestor.hpp @@ -37,7 +37,7 @@ struct PMORMQLowestCommonAncestor : Graph { in[idx] = (int)ord.size(); ord.emplace_back(idx); dep.emplace_back(d); - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (to != par) { dfs(to, idx, d + 1); ord.emplace_back(idx); diff --git a/graph/tree/rerooting.hpp b/graph/tree/rerooting.hpp index aadd36c88..ecda04031 100644 --- a/graph/tree/rerooting.hpp +++ b/graph/tree/rerooting.hpp @@ -15,31 +15,31 @@ struct ReRooting { const sum_t ident; vector subdp, dp; - ReRooting(int V, const F f, const G g, const sum_t &ident) + ReRooting(int V, const F f, const G g, const sum_t& ident) : g(V), f(f), gg(g), ident(ident), subdp(V, ident), dp(V, ident) {} - void add_edge(int u, int v, const key_t &d) { + void add_edge(int u, int v, const key_t& d) { g[u].emplace_back((Edge){v, d, ident, ident}); g[v].emplace_back((Edge){u, d, ident, ident}); } - void add_edge_bi(int u, int v, const key_t &d, const key_t &e) { + void add_edge_bi(int u, int v, const key_t& d, const key_t& e) { g[u].emplace_back((Edge){v, d, ident, ident}); g[v].emplace_back((Edge){u, e, ident, ident}); } void dfs_sub(int idx, int par) { - for (auto &e : g[idx]) { + for (auto& e : g[idx]) { if (e.to == par) continue; dfs_sub(e.to, idx); subdp[idx] = f(subdp[idx], gg(subdp[e.to], e.data)); } } - void dfs_all(int idx, int par, const sum_t &top) { + void dfs_all(int idx, int par, const sum_t& top) { sum_t buff{ident}; for (int i = 0; i < (int)g[idx].size(); i++) { - auto &e = g[idx][i]; + auto& e = g[idx][i]; e.ndp = buff; e.dp = gg(par == e.to ? top : subdp[e.to], e.data); buff = f(buff, e.dp); @@ -47,7 +47,7 @@ struct ReRooting { dp[idx] = buff; buff = ident; for (int i = (int)g[idx].size() - 1; i >= 0; i--) { - auto &e = g[idx][i]; + auto& e = g[idx][i]; if (e.to != par) dfs_all(e.to, idx, f(e.ndp, buff)); e.ndp = f(e.ndp, buff); buff = f(buff, e.dp); diff --git a/graph/tree/rmq-lowest-common-ancestor.hpp b/graph/tree/rmq-lowest-common-ancestor.hpp index 82b07c594..57a47ec6a 100644 --- a/graph/tree/rmq-lowest-common-ancestor.hpp +++ b/graph/tree/rmq-lowest-common-ancestor.hpp @@ -38,7 +38,7 @@ struct RMQLowestCommonAncestor : Graph { in[idx] = (int)ord.size(); ord.emplace_back(idx); dep.emplace_back(d); - for (auto &to : g[idx]) { + for (auto& to : g[idx]) { if (to != par) { dfs(to, idx, d + 1); ord.emplace_back(idx); diff --git a/graph/tree/static-top-tree-dp.hpp b/graph/tree/static-top-tree-dp.hpp index 3b8bb0b63..89d277012 100644 --- a/graph/tree/static-top-tree-dp.hpp +++ b/graph/tree/static-top-tree-dp.hpp @@ -7,11 +7,11 @@ struct StaticTopTreeDP { using STT = StaticTopTree; - const STT &g; + const STT& g; - const TreeDPInfo &info; + const TreeDPInfo& info; - explicit StaticTopTreeDP(const STT &g, const TreeDPInfo &info) + explicit StaticTopTreeDP(const STT& g, const TreeDPInfo& info) : g(g), info(info) { dp.resize(g.size()); dfs(g.root); diff --git a/graph/tree/static-top-tree.hpp b/graph/tree/static-top-tree.hpp index 49fe4cb75..ed764bb46 100644 --- a/graph/tree/static-top-tree.hpp +++ b/graph/tree/static-top-tree.hpp @@ -18,7 +18,7 @@ struct StaticTopTree { int root; - explicit StaticTopTree(G &g, int r = 0) : g(g), edge_to_vs(g.size() - 1) { + explicit StaticTopTree(G& g, int r = 0) : g(g), edge_to_vs(g.size() - 1) { int e_sz = 0; for (int i = 0; i < g.size(); i++) e_sz += g[i].size(); if (e_sz + 1 != g.size()) { @@ -32,18 +32,18 @@ struct StaticTopTree { vs.shrink_to_fit(); } - const Node &operator[](int k) const { return vs[k]; } + const Node& operator[](int k) const { return vs[k]; } size_t size() const { return vs.size(); } private: - G &g; + G& g; using P = pair; int dfs(int u) { int size = 1, heavy = 0; - for (auto &v : g[u]) { + for (auto& v : g[u]) { int subtree_size = dfs(v); size += subtree_size; if (heavy < subtree_size) { @@ -66,14 +66,14 @@ struct StaticTopTree { return k; } - P merge_forRake(const vector

&a) { + P merge_forRake(const vector

& a) { if (a.size() == 1) return a[0]; int size_sum = 0; - for (auto &[_, size] : a) { + for (auto& [_, size] : a) { size_sum += size; } vector

b, c; - for (auto &[it, size] : a) { + for (auto& [it, size] : a) { (size_sum > size ? b : c).emplace_back(it, size); size_sum -= size * 2; } @@ -82,14 +82,14 @@ struct StaticTopTree { return {make_node(Rake, l, r), l_size + r_size}; } - P merge_forCompress(const vector> &a) { + P merge_forCompress(const vector>& a) { if (a.size() == 1) return a[0].first; int size_sum = 0; - for (auto &[it, _] : a) { + for (auto& [it, _] : a) { size_sum += it.second; } vector> b, c; - for (auto &[it, _] : a) { + for (auto& [it, _] : a) { (size_sum > it.second ? b : c).emplace_back(it, _); size_sum -= it.second * 2; } diff --git a/graph/tree/tree-diameter.hpp b/graph/tree/tree-diameter.hpp index 61f72b6fc..e8f95a3a7 100644 --- a/graph/tree/tree-diameter.hpp +++ b/graph/tree/tree-diameter.hpp @@ -20,7 +20,7 @@ struct TreeDiameter : Graph { int now = p.second; while (now != q.second) { - for (auto &e : g[now]) { + for (auto& e : g[now]) { if (to[now] == e.to) { path.emplace_back(e); } @@ -30,14 +30,14 @@ struct TreeDiameter : Graph { return q.first; } - explicit TreeDiameter(const Graph &g) : Graph(g) {} + explicit TreeDiameter(const Graph& g) : Graph(g) {} private: vector to; pair dfs(int idx, int par) { pair ret(0, idx); - for (auto &e : g[idx]) { + for (auto& e : g[idx]) { if (e.to == par) continue; auto cost = dfs(e.to, idx); cost.first += e.cost; diff --git a/graph/tree/tree-isomorphism.hpp b/graph/tree/tree-isomorphism.hpp index 933d805be..c9b5611b2 100644 --- a/graph/tree/tree-isomorphism.hpp +++ b/graph/tree/tree-isomorphism.hpp @@ -7,13 +7,13 @@ * @brief Tree-Isomorphism(木の同型性判定) */ template -bool tree_isomorphism(const Graph &a, const Graph &b) { +bool tree_isomorphism(const Graph& a, const Graph& b) { if (a.size() != b.size()) return false; const int N = (int)a.size(); using pvi = pair, vector >; - auto get_uku = [&](const Graph &t, int e) { + auto get_uku = [&](const Graph& t, int e) { stack > st; st.emplace(e, -1); vector dep(N, -1), par(N); @@ -21,7 +21,7 @@ bool tree_isomorphism(const Graph &a, const Graph &b) { auto p = st.top(); if (dep[p.first] == -1) { dep[p.first] = p.second == -1 ? 0 : dep[p.second] + 1; - for (auto &to : t[p.first]) + for (auto& to : t[p.first]) if (to != p.second) st.emplace(to, p.first); } else { par[p.first] = p.second; @@ -31,7 +31,7 @@ bool tree_isomorphism(const Graph &a, const Graph &b) { return make_pair(dep, par); }; - auto solve = [&](const pvi &latte, const pvi &malta) { + auto solve = [&](const pvi& latte, const pvi& malta) { int d = *max_element(begin(latte.first), end(latte.first)); if (d != *max_element(begin(malta.first), end(malta.first))) return false; @@ -43,25 +43,25 @@ bool tree_isomorphism(const Graph &a, const Graph &b) { for (int i = d; i >= 0; i--) { map, int> ord; - for (auto &idx : latte_d[i]) { + for (auto& idx : latte_d[i]) { sort(begin(latte_key[idx]), end(latte_key[idx])); ord[latte_key[idx]]++; } - for (auto &idx : malta_d[i]) { + for (auto& idx : malta_d[i]) { sort(begin(malta_key[idx]), end(malta_key[idx])); if (--ord[malta_key[idx]] < 0) return false; } if (i == 0) return ord.size() == 1; int ptr = 0; - for (auto &p : ord) { + for (auto& p : ord) { if (p.second != 0) return false; p.second = ptr++; } - for (auto &idx : latte_d[i]) { + for (auto& idx : latte_d[i]) { latte_key[latte.second[idx]].emplace_back(ord[latte_key[idx]]); } - for (auto &idx : malta_d[i]) { + for (auto& idx : malta_d[i]) { malta_key[malta.second[idx]].emplace_back(ord[malta_key[idx]]); } } diff --git a/math/combinatorics/arbitrary-mod-int.hpp b/math/combinatorics/arbitrary-mod-int.hpp index c935091bb..d0f6677f2 100644 --- a/math/combinatorics/arbitrary-mod-int.hpp +++ b/math/combinatorics/arbitrary-mod-int.hpp @@ -7,24 +7,24 @@ struct ArbitraryModInt { : x(y >= 0 ? y % get_mod() : (get_mod() - (-y) % get_mod()) % get_mod()) { } - static int &get_mod() { + static int& get_mod() { static int mod = 0; return mod; } static void set_mod(int md) { get_mod() = md; } - ArbitraryModInt &operator+=(const ArbitraryModInt &p) { + ArbitraryModInt& operator+=(const ArbitraryModInt& p) { if ((x += p.x) >= get_mod()) x -= get_mod(); return *this; } - ArbitraryModInt &operator-=(const ArbitraryModInt &p) { + ArbitraryModInt& operator-=(const ArbitraryModInt& p) { if ((x += get_mod() - p.x) >= get_mod()) x -= get_mod(); return *this; } - ArbitraryModInt &operator*=(const ArbitraryModInt &p) { + ArbitraryModInt& operator*=(const ArbitraryModInt& p) { unsigned long long a = (unsigned long long)x * p.x; unsigned xh = (unsigned)(a >> 32), xl = (unsigned)a, d, m; asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(get_mod())); @@ -32,32 +32,32 @@ struct ArbitraryModInt { return *this; } - ArbitraryModInt &operator/=(const ArbitraryModInt &p) { + ArbitraryModInt& operator/=(const ArbitraryModInt& p) { *this *= p.inverse(); return *this; } ArbitraryModInt operator-() const { return ArbitraryModInt(-x); } - ArbitraryModInt operator+(const ArbitraryModInt &p) const { + ArbitraryModInt operator+(const ArbitraryModInt& p) const { return ArbitraryModInt(*this) += p; } - ArbitraryModInt operator-(const ArbitraryModInt &p) const { + ArbitraryModInt operator-(const ArbitraryModInt& p) const { return ArbitraryModInt(*this) -= p; } - ArbitraryModInt operator*(const ArbitraryModInt &p) const { + ArbitraryModInt operator*(const ArbitraryModInt& p) const { return ArbitraryModInt(*this) *= p; } - ArbitraryModInt operator/(const ArbitraryModInt &p) const { + ArbitraryModInt operator/(const ArbitraryModInt& p) const { return ArbitraryModInt(*this) /= p; } - bool operator==(const ArbitraryModInt &p) const { return x == p.x; } + bool operator==(const ArbitraryModInt& p) const { return x == p.x; } - bool operator!=(const ArbitraryModInt &p) const { return x != p.x; } + bool operator!=(const ArbitraryModInt& p) const { return x != p.x; } ArbitraryModInt inverse() const { int a = x, b = get_mod(), u = 1, v = 0, t; @@ -79,11 +79,11 @@ struct ArbitraryModInt { return ret; } - friend ostream &operator<<(ostream &os, const ArbitraryModInt &p) { + friend ostream& operator<<(ostream& os, const ArbitraryModInt& p) { return os << p.x; } - friend istream &operator>>(istream &is, ArbitraryModInt &a) { + friend istream& operator>>(istream& is, ArbitraryModInt& a) { int64_t t; is >> t; a = ArbitraryModInt(t); diff --git a/math/combinatorics/lagrange-polynomial-2.hpp b/math/combinatorics/lagrange-polynomial-2.hpp index a12b63a32..499cb42ff 100644 --- a/math/combinatorics/lagrange-polynomial-2.hpp +++ b/math/combinatorics/lagrange-polynomial-2.hpp @@ -2,7 +2,7 @@ * @brief Lagrange Polynomial(多項式補間, 係数) */ template -vector lagrange_polynomial(const vector &x, const vector &y) { +vector lagrange_polynomial(const vector& x, const vector& y) { int k = (int)x.size() - 1; vector f(k + 1), dp(k + 2); diff --git a/math/combinatorics/lagrange-polynomial-3.hpp b/math/combinatorics/lagrange-polynomial-3.hpp index d5038344f..b2b898def 100644 --- a/math/combinatorics/lagrange-polynomial-3.hpp +++ b/math/combinatorics/lagrange-polynomial-3.hpp @@ -2,8 +2,8 @@ * @brief Lagrange Polynomial(多項式補間, 値) */ template -vector lagrange_polynomial(const vector &y, int64_t T, const int &m, - const F &multiply) { +vector lagrange_polynomial(const vector& y, int64_t T, const int& m, + const F& multiply) { int k = (int)y.size() - 1; T %= Mint::mod(); if (T <= k) { diff --git a/math/combinatorics/lagrange-polynomial.hpp b/math/combinatorics/lagrange-polynomial.hpp index 75430c97a..7ab463be1 100644 --- a/math/combinatorics/lagrange-polynomial.hpp +++ b/math/combinatorics/lagrange-polynomial.hpp @@ -2,7 +2,7 @@ * @brief Lagrange Polynomial(多項式補間, 値) */ template -T lagrange_polynomial(const vector &y, int64_t t) { +T lagrange_polynomial(const vector& y, int64_t t) { int N = y.size() - 1; Combination comb(N); if (t <= N) return y[t]; diff --git a/math/combinatorics/mod-pow.hpp b/math/combinatorics/mod-pow.hpp index 7d7415204..d4d9fd777 100644 --- a/math/combinatorics/mod-pow.hpp +++ b/math/combinatorics/mod-pow.hpp @@ -3,7 +3,7 @@ * */ template -T mod_pow(T x, int64_t n, const T &p) { +T mod_pow(T x, int64_t n, const T& p) { T ret = 1; while (n > 0) { if (n & 1) (ret *= x) %= p; diff --git a/math/combinatorics/mod-sqrt.hpp b/math/combinatorics/mod-sqrt.hpp index 5e472f672..699131546 100644 --- a/math/combinatorics/mod-sqrt.hpp +++ b/math/combinatorics/mod-sqrt.hpp @@ -2,7 +2,7 @@ * @brief Mod Sqrt */ template -T mod_sqrt(const T &a, const T &p) { +T mod_sqrt(const T& a, const T& p) { if (a == 0) return 0; if (p == 2) return a; if (mod_pow(a, (p - 1) >> 1, p) != 1) return -1; diff --git a/math/combinatorics/mod-tetration.hpp b/math/combinatorics/mod-tetration.hpp index e9777ca49..aaf844a9e 100644 --- a/math/combinatorics/mod-tetration.hpp +++ b/math/combinatorics/mod-tetration.hpp @@ -6,7 +6,7 @@ * */ template -T mod_tetration(const T &a, const T &b, const T &m) { +T mod_tetration(const T& a, const T& b, const T& m) { if (m == 1) return 0; if (a == 0) return !(b & 1); if (b == 0) return 1; diff --git a/math/combinatorics/modint-2-61m1.hpp b/math/combinatorics/modint-2-61m1.hpp index 9b1dcb2c3..9d2b31d2b 100644 --- a/math/combinatorics/modint-2-61m1.hpp +++ b/math/combinatorics/modint-2-61m1.hpp @@ -11,41 +11,41 @@ struct ModInt_2_61m1 { explicit ModInt_2_61m1(u64 a) : x{a} {} - mint &operator+=(const mint &p) { + mint& operator+=(const mint& p) { if ((x += p.x) >= mod()) x -= mod(); return *this; } - mint &operator-=(const mint &p) { + mint& operator-=(const mint& p) { if ((x += mod() - p.x) >= mod()) x -= mod(); return *this; } - mint &operator*=(const mint &p) { + mint& operator*=(const mint& p) { u128 c = (u128)x * p.x; x = u64(c >> 61) + u64(c & mod()); if (x >= mod()) x -= mod(); return *this; } - mint &operator/=(const mint &p) { + mint& operator/=(const mint& p) { *this *= p.inv(); return *this; } mint operator-() const { return mint() - *this; } - mint operator+(const mint &p) const { return mint(*this) += p; } + mint operator+(const mint& p) const { return mint(*this) += p; } - mint operator-(const mint &p) const { return mint(*this) -= p; } + mint operator-(const mint& p) const { return mint(*this) -= p; } - mint operator*(const mint &p) const { return mint(*this) *= p; } + mint operator*(const mint& p) const { return mint(*this) *= p; } - mint operator/(const mint &p) const { return mint(*this) /= p; } + mint operator/(const mint& p) const { return mint(*this) /= p; } - bool operator==(const mint &p) const { return x == p.x; } + bool operator==(const mint& p) const { return x == p.x; } - bool operator!=(const mint &p) const { return x != p.x; } + bool operator!=(const mint& p) const { return x != p.x; } u64 val() const { return x; } @@ -61,11 +61,11 @@ struct ModInt_2_61m1 { mint inv() const { return pow(mod() - 2); } - friend ostream &operator<<(ostream &os, const mint &p) { + friend ostream& operator<<(ostream& os, const mint& p) { return os << p.val(); } - friend istream &operator>>(istream &is, mint &a) { + friend istream& operator>>(istream& is, mint& a) { u64 t; is >> t; a = mint(t); diff --git a/math/combinatorics/montgomery-mod-int.hpp b/math/combinatorics/montgomery-mod-int.hpp index edf48c75a..4db821582 100644 --- a/math/combinatorics/montgomery-mod-int.hpp +++ b/math/combinatorics/montgomery-mod-int.hpp @@ -28,48 +28,48 @@ struct MontgomeryModInt { public: MontgomeryModInt() : x{} {} - MontgomeryModInt(const i64 &a) + MontgomeryModInt(const i64& a) : x(reduce(u64(fast ? a : (a % mod() + mod())) * n2)) {} - static constexpr u32 reduce(const u64 &b) { + static constexpr u32 reduce(const u64& b) { return u32(b >> 32) + mod() - u32((u64(u32(b) * r) * mod()) >> 32); } - mint &operator+=(const mint &p) { + mint& operator+=(const mint& p) { if (i32(x += p.x - 2 * mod()) < 0) x += 2 * mod(); return *this; } - mint &operator-=(const mint &p) { + mint& operator-=(const mint& p) { if (i32(x -= p.x) < 0) x += 2 * mod(); return *this; } - mint &operator*=(const mint &p) { + mint& operator*=(const mint& p) { x = reduce(u64(x) * p.x); return *this; } - mint &operator/=(const mint &p) { + mint& operator/=(const mint& p) { *this *= p.inv(); return *this; } mint operator-() const { return mint() - *this; } - mint operator+(const mint &p) const { return mint(*this) += p; } + mint operator+(const mint& p) const { return mint(*this) += p; } - mint operator-(const mint &p) const { return mint(*this) -= p; } + mint operator-(const mint& p) const { return mint(*this) -= p; } - mint operator*(const mint &p) const { return mint(*this) *= p; } + mint operator*(const mint& p) const { return mint(*this) *= p; } - mint operator/(const mint &p) const { return mint(*this) /= p; } + mint operator/(const mint& p) const { return mint(*this) /= p; } - bool operator==(const mint &p) const { + bool operator==(const mint& p) const { return (x >= mod() ? x - mod() : x) == (p.x >= mod() ? p.x - mod() : p.x); } - bool operator!=(const mint &p) const { + bool operator!=(const mint& p) const { return (x >= mod() ? x - mod() : x) != (p.x >= mod() ? p.x - mod() : p.x); } @@ -90,11 +90,11 @@ struct MontgomeryModInt { mint inv() const { return pow(mod() - 2); } - friend ostream &operator<<(ostream &os, const mint &p) { + friend ostream& operator<<(ostream& os, const mint& p) { return os << p.val(); } - friend istream &operator>>(istream &is, mint &a) { + friend istream& operator>>(istream& is, mint& a) { i64 t; is >> t; a = mint(t); diff --git a/math/combinatorics/sample-point-shift.hpp b/math/combinatorics/sample-point-shift.hpp index ef0a4682e..6696dfd76 100644 --- a/math/combinatorics/sample-point-shift.hpp +++ b/math/combinatorics/sample-point-shift.hpp @@ -4,8 +4,8 @@ * @brief Sample Point Shift(標本点シフト) */ template -vector sample_point_shift(const vector &ys, const Mint &m, - const F &multiply) { +vector sample_point_shift(const vector& ys, const Mint& m, + const F& multiply) { Enumeration comb; int d = (int)ys.size() - 1; vector f(d + 1), g(d * 2 + 1); diff --git a/math/combinatorics/sum-of-arithmetic-sequence.hpp b/math/combinatorics/sum-of-arithmetic-sequence.hpp index a7e311713..bb4f91a59 100644 --- a/math/combinatorics/sum-of-arithmetic-sequence.hpp +++ b/math/combinatorics/sum-of-arithmetic-sequence.hpp @@ -2,6 +2,6 @@ * @brief Sum of Arithmetic Sequence(等差数列の和) */ template -Mint sum_of_arithmetic_sequence(const Mint &a, const Mint &d, const Mint &n) { +Mint sum_of_arithmetic_sequence(const Mint& a, const Mint& d, const Mint& n) { return n * (2 * a + (n - 1) * d) / 2; } diff --git a/math/combinatorics/sum-of-geometric-sequence.hpp b/math/combinatorics/sum-of-geometric-sequence.hpp index ab1f2c0c8..8baecf7c9 100644 --- a/math/combinatorics/sum-of-geometric-sequence.hpp +++ b/math/combinatorics/sum-of-geometric-sequence.hpp @@ -2,7 +2,7 @@ * @brief Sum of Geometric Sequence(等比数列の和) */ template -Mint sum_of_geometric_sequence(const Mint &a, const Mint &r, const int64_t &n) { +Mint sum_of_geometric_sequence(const Mint& a, const Mint& r, const int64_t& n) { assert(r != Mint(0)); return r == Mint(1) ? a * n : a * (r.pow(n) - 1) / (r - 1); } diff --git a/math/combinatorics/vectorize-mod-int.hpp b/math/combinatorics/vectorize-mod-int.hpp index 257052ee7..134516125 100644 --- a/math/combinatorics/vectorize-mod-int.hpp +++ b/math/combinatorics/vectorize-mod-int.hpp @@ -22,21 +22,21 @@ struct alignas(32) VectorizeModInt { VectorizeModInt() : x{} {} - inline VectorizeModInt(const i32 &v) : x(_mm256_set1_epi32(v)) {} + inline VectorizeModInt(const i32& v) : x(_mm256_set1_epi32(v)) {} - inline VectorizeModInt(const i32 &v0, const i32 &v1, const i32 &v2, - const i32 &v3, const i32 &v4, const i32 &v5, - const i32 &v6, const i32 &v7) + inline VectorizeModInt(const i32& v0, const i32& v1, const i32& v2, + const i32& v3, const i32& v4, const i32& v5, + const i32& v6, const i32& v7) : x(_mm256_setr_epi32(v0, v1, v2, v3, v4, v5, v6, v7)) {} - inline VectorizeModInt(const void *vs) - : x(_mm256_loadu_si256((__m256i *)vs)) {} + inline VectorizeModInt(const void* vs) + : x(_mm256_loadu_si256((__m256i*)vs)) {} - inline VectorizeModInt(const __m256i &x) : x(x) {} + inline VectorizeModInt(const __m256i& x) : x(x) {} - inline void store(const void *vs) { _mm256_storeu_si256((__m256i *)vs, x); } + inline void store(const void* vs) { _mm256_storeu_si256((__m256i*)vs, x); } - static inline __m256i _mm256_mulhi_epi32(const __m256i &a, const __m256i &b) { + static inline __m256i _mm256_mulhi_epi32(const __m256i& a, const __m256i& b) { auto prod02 = _mm256_mul_epu32(a, b); auto prod13 = _mm256_mul_epu32(_mm256_shuffle_epi32(a, 0xf5), _mm256_shuffle_epi32(b, 0xf5)); @@ -44,7 +44,7 @@ struct alignas(32) VectorizeModInt { _mm256_unpackhi_epi32(prod02, prod13)); } - static inline __m256i reduce(const __m256i &lo, const __m256i &hi) { + static inline __m256i reduce(const __m256i& lo, const __m256i& hi) { // u32(b >> 32) + mod - u32((u64(u32(b) * r) * mod) >> 32) return _mm256_add_epi32( _mm256_sub_epi32(hi, @@ -52,30 +52,30 @@ struct alignas(32) VectorizeModInt { m1); } - Mints inline &operator+=(const Mints &p) { + Mints inline& operator+=(const Mints& p) { // if(int(x += p.x - 2 * mod) < 0) x += 2 * mod; const auto c = _mm256_sub_epi32(_mm256_add_epi32(x, p.x), m2); x = _mm256_add_epi32(c, _mm256_and_si256(_mm256_cmpgt_epi32(m0, c), m2)); return *this; } - Mints inline &operator-=(const Mints &p) { + Mints inline& operator-=(const Mints& p) { // if(int(x -= p.x) < 0) x += 2 * mod; const auto c = _mm256_sub_epi32(x, p.x); x = _mm256_add_epi32(c, _mm256_and_si256(_mm256_cmpgt_epi32(m0, c), m2)); return *this; } - Mints inline &operator*=(const Mints &p) { + Mints inline& operator*=(const Mints& p) { x = reduce(_mm256_mullo_epi32(x, p.x), _mm256_mulhi_epi32(x, p.x)); return *this; } - Mints inline operator+(const Mints &p) const { return Mints(*this) += p; } + Mints inline operator+(const Mints& p) const { return Mints(*this) += p; } - Mints inline operator-(const Mints &p) const { return Mints(*this) -= p; } + Mints inline operator-(const Mints& p) const { return Mints(*this) -= p; } - Mints inline operator*(const Mints &p) const { return Mints(*this) *= p; } + Mints inline operator*(const Mints& p) const { return Mints(*this) *= p; } }; __attribute__((aligned(32))) __m256i VectorizeModInt::m0; diff --git a/math/fft/arbitrary-mod-convolution-long.hpp b/math/fft/arbitrary-mod-convolution-long.hpp index dbbc31911..13ae0b53d 100644 --- a/math/fft/arbitrary-mod-convolution-long.hpp +++ b/math/fft/arbitrary-mod-convolution-long.hpp @@ -5,7 +5,7 @@ struct ArbitraryModConvolutionLong { ArbitraryModConvolutionLong() = default; - vector multiply(const vector &a, const vector &b, int need = -1) { + vector multiply(const vector& a, const vector& b, int need = -1) { if (need == -1) need = a.size() + b.size() - 1; int nbase = 0; while ((1 << nbase) < need) nbase++; diff --git a/math/fft/arbitrary-mod-convolution.hpp b/math/fft/arbitrary-mod-convolution.hpp index 8c6b2be01..15c70678e 100644 --- a/math/fft/arbitrary-mod-convolution.hpp +++ b/math/fft/arbitrary-mod-convolution.hpp @@ -10,7 +10,7 @@ struct ArbitraryModConvolution { ArbitraryModConvolution() = default; - static vector multiply(const vector &a, const vector &b, + static vector multiply(const vector& a, const vector& b, int need = -1) { if (need == -1) need = a.size() + b.size() - 1; int nbase = 0; diff --git a/math/fft/fast-fourier-transform.hpp b/math/fft/fast-fourier-transform.hpp index 557e0f4a9..55fe61dfd 100644 --- a/math/fft/fast-fourier-transform.hpp +++ b/math/fft/fast-fourier-transform.hpp @@ -8,11 +8,11 @@ struct C { C(real x, real y) : x(x), y(y) {} - inline C operator+(const C &c) const { return C(x + c.x, y + c.y); } + inline C operator+(const C& c) const { return C(x + c.x, y + c.y); } - inline C operator-(const C &c) const { return C(x - c.x, y - c.y); } + inline C operator-(const C& c) const { return C(x - c.x, y - c.y); } - inline C operator*(const C &c) const { + inline C operator*(const C& c) const { return C(x * c.x - y * c.y, x * c.y + y * c.x); } @@ -42,7 +42,7 @@ void ensure_base(int nbase) { } } -void fft(vector &a, int n) { +void fft(vector& a, int n) { assert((n & (n - 1)) == 0); int zeros = __builtin_ctz(n); ensure_base(zeros); @@ -63,7 +63,7 @@ void fft(vector &a, int n) { } } -vector multiply(const vector &a, const vector &b) { +vector multiply(const vector& a, const vector& b) { int need = (int)a.size() + (int)b.size() - 1; int nbase = 1; while ((1 << nbase) < need) nbase++; diff --git a/math/fft/fast-walsh-hadamard-transform.hpp b/math/fft/fast-walsh-hadamard-transform.hpp index 8d429eb5e..6f09c6a95 100644 --- a/math/fft/fast-walsh-hadamard-transform.hpp +++ b/math/fft/fast-walsh-hadamard-transform.hpp @@ -2,7 +2,7 @@ * @brief Fast Walsh Hadamard Transform (高速ウォルシュアダマール変換) */ template -void fast_walsh_hadamard_transform(vector &f, bool inv = false) { +void fast_walsh_hadamard_transform(vector& f, bool inv = false) { const int n = (int)f.size(); assert((n & (n - 1)) == 0); for (int i = 1; i < n; i <<= 1) { @@ -16,6 +16,6 @@ void fast_walsh_hadamard_transform(vector &f, bool inv = false) { } if (inv) { T inv_n = T(1) / n; - for (auto &x : f) x *= inv_n; + for (auto& x : f) x *= inv_n; } } diff --git a/math/fft/number-theoretic-transform-friendly-mod-int.hpp b/math/fft/number-theoretic-transform-friendly-mod-int.hpp index e7ffdbbd9..9e9350add 100644 --- a/math/fft/number-theoretic-transform-friendly-mod-int.hpp +++ b/math/fft/number-theoretic-transform-friendly-mod-int.hpp @@ -44,7 +44,7 @@ struct NumberTheoreticTransformFriendlyModInt { } } - static void ntt(vector &a) { + static void ntt(vector& a) { init(); const int n = (int)a.size(); assert((n & (n - 1)) == 0); @@ -104,7 +104,7 @@ struct NumberTheoreticTransformFriendlyModInt { } } - static void intt(vector &a, bool f = true) { + static void intt(vector& a, bool f = true) { init(); const int n = (int)a.size(); assert((n & (n - 1)) == 0); diff --git a/math/fft/number-theoretic-transform.hpp b/math/fft/number-theoretic-transform.hpp index c95707be1..12ff412d0 100644 --- a/math/fft/number-theoretic-transform.hpp +++ b/math/fft/number-theoretic-transform.hpp @@ -54,7 +54,7 @@ struct NumberTheoreticTransform { } } - void ntt(vector &a) { + void ntt(vector& a) { const int n = (int)a.size(); assert((n & (n - 1)) == 0); int zeros = __builtin_ctz(n); diff --git a/math/fft/subset-convolution.hpp b/math/fft/subset-convolution.hpp index 3c0ce2671..2930ecb41 100644 --- a/math/fft/subset-convolution.hpp +++ b/math/fft/subset-convolution.hpp @@ -18,19 +18,19 @@ struct SubsetConvolution { } } - static inline void add(fps &f, const fps &g, int d) { + static inline void add(fps& f, const fps& g, int d) { for (int i = 0; i < d; i++) { f[i] += g[i]; } } - static inline void sub(fps &f, const fps &g, int d) { + static inline void sub(fps& f, const fps& g, int d) { for (int i = d; i <= s; i++) { f[i] -= g[i]; } } - static void zeta_transform(vector &F) { + static void zeta_transform(vector& F) { const int n = (int)F.size(); assert((n & (n - 1)) == 0); init(); @@ -43,7 +43,7 @@ struct SubsetConvolution { } } - static void moebius_transform(vector &F) { + static void moebius_transform(vector& F) { const int n = (int)F.size(); assert((n & (n - 1)) == 0); init(); @@ -56,7 +56,7 @@ struct SubsetConvolution { } } - static vector lift(const vector &f) { + static vector lift(const vector& f) { const int n = (int)f.size(); init(); vector F(n); @@ -67,7 +67,7 @@ struct SubsetConvolution { return F; } - static vector unlift(const vector &F) { + static vector unlift(const vector& F) { const int n = (int)F.size(); init(); vector f(n); @@ -77,7 +77,7 @@ struct SubsetConvolution { return f; } - static void prod(vector &F, const vector &G) { + static void prod(vector& F, const vector& G) { int n = (int)F.size(); int d = __builtin_ctz(n); for (int i = 0; i < n; i++) { @@ -91,7 +91,7 @@ struct SubsetConvolution { } } - static vector multiply(const vector &f, const vector &g) { + static vector multiply(const vector& f, const vector& g) { auto F = lift(f), G = lift(g); zeta_transform(F); zeta_transform(G); diff --git a/math/fft/subset-zeta-moebius-transform.hpp b/math/fft/subset-zeta-moebius-transform.hpp index 15276ec00..e11d3a9ec 100644 --- a/math/fft/subset-zeta-moebius-transform.hpp +++ b/math/fft/subset-zeta-moebius-transform.hpp @@ -2,7 +2,7 @@ * @brief Subset Zeta/Moebius Transform (下位集合のゼータ/メビウス変換) */ template -void subset_zeta_transform(vector &f) { +void subset_zeta_transform(vector& f) { const int n = (int)f.size(); assert((n & (n - 1)) == 0); for (int i = 1; i < n; i <<= 1) { @@ -15,7 +15,7 @@ void subset_zeta_transform(vector &f) { } template -void subset_moebius_transform(vector &f) { +void subset_moebius_transform(vector& f) { const int n = (int)f.size(); assert((n & (n - 1)) == 0); for (int i = 1; i < n; i <<= 1) { diff --git a/math/fft/superset-zeta-moebius-transform-simd.hpp b/math/fft/superset-zeta-moebius-transform-simd.hpp index 88301c665..aa390d4e5 100644 --- a/math/fft/superset-zeta-moebius-transform-simd.hpp +++ b/math/fft/superset-zeta-moebius-transform-simd.hpp @@ -4,7 +4,7 @@ * @brief Superset Zeta/Moebius Transform SIMD (上位集合のゼータ/メビウス変換, * SIMD) */ -__attribute__((target("avx2"))) void superset_zeta_transform_simd(int *buf, +__attribute__((target("avx2"))) void superset_zeta_transform_simd(int* buf, int mod, int n) { assert((n & (n - 1)) == 0); @@ -23,28 +23,28 @@ __attribute__((target("avx2"))) void superset_zeta_transform_simd(int *buf, } } else if (i == 4) { for (int k = 0; k < i; k += 4) { - auto a = _mm_loadu_si128((__m128i *)(buf + j + k)); - auto b = _mm_loadu_si128((__m128i *)(buf + j + k + i)); + auto a = _mm_loadu_si128((__m128i*)(buf + j + k)); + auto b = _mm_loadu_si128((__m128i*)(buf + j + k + i)); a = _mm_add_epi32(a, b); a = _mm_sub_epi32( a, _mm_and_si128(_mm_cmpgt_epi32(a, m_mod_one2), m_mod2)); - _mm_storeu_si128((__m128i *)(buf + j + k), a); + _mm_storeu_si128((__m128i*)(buf + j + k), a); } } else { for (int k = 0; k < i; k += 8) { - auto a = _mm256_loadu_si256((__m256i *)(buf + j + k)); - auto b = _mm256_loadu_si256((__m256i *)(buf + j + k + i)); + auto a = _mm256_loadu_si256((__m256i*)(buf + j + k)); + auto b = _mm256_loadu_si256((__m256i*)(buf + j + k + i)); a = _mm256_add_epi32(a, b); a = _mm256_sub_epi32( a, _mm256_and_si256(_mm256_cmpgt_epi32(a, m_mod_one), m_mod)); - _mm256_storeu_si256((__m256i *)(buf + j + k), a); + _mm256_storeu_si256((__m256i*)(buf + j + k), a); } } } } } -__attribute__((target("avx2"))) void superset_moebius_transform_simd(int *buf, +__attribute__((target("avx2"))) void superset_moebius_transform_simd(int* buf, int mod, int n) { assert((n & (n - 1)) == 0); @@ -61,21 +61,21 @@ __attribute__((target("avx2"))) void superset_moebius_transform_simd(int *buf, } } else if (i == 4) { for (int k = 0; k < i; k += 4) { - auto a = _mm_loadu_si128((__m128i *)(buf + j + k)); - auto b = _mm_loadu_si128((__m128i *)(buf + j + k + i)); + auto a = _mm_loadu_si128((__m128i*)(buf + j + k)); + auto b = _mm_loadu_si128((__m128i*)(buf + j + k + i)); a = _mm_sub_epi32(a, b); a = _mm_add_epi32(a, _mm_and_si128(_mm_cmpgt_epi32(m_zero2, a), m_mod2)); - _mm_storeu_si128((__m128i *)(buf + j + k), a); + _mm_storeu_si128((__m128i*)(buf + j + k), a); } } else { for (int k = 0; k < i; k += 8) { - auto a = _mm256_loadu_si256((__m256i *)(buf + j + k)); - auto b = _mm256_loadu_si256((__m256i *)(buf + j + k + i)); + auto a = _mm256_loadu_si256((__m256i*)(buf + j + k)); + auto b = _mm256_loadu_si256((__m256i*)(buf + j + k + i)); a = _mm256_sub_epi32(a, b); a = _mm256_add_epi32( a, _mm256_and_si256(_mm256_cmpgt_epi32(m_zero, a), m_mod)); - _mm256_storeu_si256((__m256i *)(buf + j + k), a); + _mm256_storeu_si256((__m256i*)(buf + j + k), a); } } } @@ -83,7 +83,7 @@ __attribute__((target("avx2"))) void superset_moebius_transform_simd(int *buf, } template -int *bitwise_and_convolution_simd(int *f, int *g, int n) { +int* bitwise_and_convolution_simd(int* f, int* g, int n) { assert((n & (n - 1)) == 0); superset_zeta_transform_simd(f, mod, n); superset_zeta_transform_simd(g, mod, n); diff --git a/math/fft/superset-zeta-moebius-transform.hpp b/math/fft/superset-zeta-moebius-transform.hpp index 56193edd2..2b78efcc1 100644 --- a/math/fft/superset-zeta-moebius-transform.hpp +++ b/math/fft/superset-zeta-moebius-transform.hpp @@ -2,7 +2,7 @@ * @brief Superset Zeta/Moebius Transform (上位集合のゼータ/メビウス変換) */ template -void superset_zeta_transform(vector &f) { +void superset_zeta_transform(vector& f) { const int n = (int)f.size(); assert((n & (n - 1)) == 0); for (int i = 1; i < n; i <<= 1) { @@ -15,7 +15,7 @@ void superset_zeta_transform(vector &f) { } template -void superset_moebius_transform(vector &f) { +void superset_moebius_transform(vector& f) { const int n = (int)f.size(); assert((n & (n - 1)) == 0); for (int i = 1; i < n; i <<= 1) { diff --git a/math/fps/berlekamp-massey.hpp b/math/fps/berlekamp-massey.hpp index 301cf1064..70a527bb9 100644 --- a/math/fps/berlekamp-massey.hpp +++ b/math/fps/berlekamp-massey.hpp @@ -2,7 +2,7 @@ * @brief Berlekamp Massey */ template