diff --git a/DataStructure/DSU/DisjointSet.h.md b/DataStructure/DSU/DisjointSet.h.md index 0f28ff9..6e9248d 100644 --- a/DataStructure/DSU/DisjointSet.h.md +++ b/DataStructure/DSU/DisjointSet.h.md @@ -15,6 +15,9 @@ data: - icon: ':heavy_check_mark:' path: Graph/tests/aizu_grl_2_a_mst.test.cpp title: Graph/tests/aizu_grl_2_a_mst.test.cpp + - icon: ':heavy_check_mark:' + path: Graph/tests/yosupo_mst.test.cpp + title: Graph/tests/yosupo_mst.test.cpp _isVerificationFailed: false _pathExtension: h _verificationStatusIcon: ':heavy_check_mark:' @@ -47,6 +50,7 @@ data: verifiedWith: - DataStructure/test/aizu_dsl_1_a_dsu.test.cpp - DataStructure/test/dsu.test.cpp + - Graph/tests/yosupo_mst.test.cpp - Graph/tests/aizu_grl_2_a_mst.test.cpp documentation_of: DataStructure/DSU/DisjointSet.h layout: document diff --git a/Graph/mst.h.md b/Graph/mst.h.md index 63fc5cb..8f04be1 100644 --- a/Graph/mst.h.md +++ b/Graph/mst.h.md @@ -9,6 +9,9 @@ data: - icon: ':heavy_check_mark:' path: Graph/tests/aizu_grl_2_a_mst.test.cpp title: Graph/tests/aizu_grl_2_a_mst.test.cpp + - icon: ':heavy_check_mark:' + path: Graph/tests/yosupo_mst.test.cpp + title: Graph/tests/yosupo_mst.test.cpp _isVerificationFailed: false _pathExtension: h _verificationStatusIcon: ':heavy_check_mark:' @@ -25,36 +28,37 @@ data: \ lab[v] = u;\n return true;\n }\n\n bool same_component(int u, int\ \ v) {\n return getRoot(u) == getRoot(v);\n }\n\n int component_size(int\ \ u) {\n return -lab[getRoot(u)];\n }\n};\n// }}}\n#line 9 \"Graph/mst.h\"\ - \n\n// MST {{{\nusing ll = long long;\nstruct Edge {\n int u, v;\n ll c;\n\ - };\nbool operator < (const Edge& a, const Edge& b) {\n return a.c < b.c;\n\ - }\nostream& operator << (ostream& out, const Edge& e) {\n out << e.u << \"\ - \ - \" << e.v << \" [\" << e.c << ']';\n return out;\n}\nstd::pair>\ - \ mst(\n int n,\n std::vector edges) {\n std::sort(edges.begin(),\ - \ edges.end());\n\n DSU dsu(n + 1); // tolerate 1-based index\n ll total\ - \ = 0;\n vector tree;\n for (const auto& e : edges) {\n const\ - \ auto [u, v, c] = e;\n if (dsu.merge(u, v)) {\n total += c;\n\ + \n\n// MST {{{\nusing ll = long long;\ntemplate\nstd::pair> mst(\n int n,\n std::vector edges)\ + \ {\n std::sort(edges.begin(), edges.end());\n\n DSU dsu(n + 1); // tolerate\ + \ 1-based index\n ll total = 0;\n vector tree;\n for (const auto&\ + \ e : edges) {\n if (dsu.merge(e.u, e.v)) {\n total += e.c;\n\ \ tree.push_back(e);\n }\n }\n return {total, tree};\n\ - }\n// }}}\n" + }\nstruct Edge {\n int u, v;\n ll c;\n};\nbool operator < (const Edge& a,\ + \ const Edge& b) {\n return a.c < b.c;\n}\nostream& operator << (ostream& out,\ + \ const Edge& e) {\n out << e.u << \" - \" << e.v << \" [\" << e.c << ']';\n\ + \ return out;\n}\n// }}}\n" code: "// MST. 0-based index\n//\n// Returns:\n// {mst cost, edges in mst}\n//\n\ // If graph is not connected, returns forest (number of edges will be < n-1)\n\ \n#include \"../DataStructure/DSU/DisjointSet.h\"\n\n// MST {{{\nusing ll = long\ - \ long;\nstruct Edge {\n int u, v;\n ll c;\n};\nbool operator < (const Edge&\ - \ a, const Edge& b) {\n return a.c < b.c;\n}\nostream& operator << (ostream&\ - \ out, const Edge& e) {\n out << e.u << \" - \" << e.v << \" [\" << e.c <<\ - \ ']';\n return out;\n}\nstd::pair> mst(\n int\ - \ n,\n std::vector edges) {\n std::sort(edges.begin(), edges.end());\n\ - \n DSU dsu(n + 1); // tolerate 1-based index\n ll total = 0;\n vector\ - \ tree;\n for (const auto& e : edges) {\n const auto [u, v, c] = e;\n\ - \ if (dsu.merge(u, v)) {\n total += c;\n tree.push_back(e);\n\ - \ }\n }\n return {total, tree};\n}\n// }}}\n" + \ long;\ntemplate\nstd::pair> mst(\n \ + \ int n,\n std::vector edges) {\n std::sort(edges.begin(),\ + \ edges.end());\n\n DSU dsu(n + 1); // tolerate 1-based index\n ll total\ + \ = 0;\n vector tree;\n for (const auto& e : edges) {\n if\ + \ (dsu.merge(e.u, e.v)) {\n total += e.c;\n tree.push_back(e);\n\ + \ }\n }\n return {total, tree};\n}\nstruct Edge {\n int u, v;\n\ + \ ll c;\n};\nbool operator < (const Edge& a, const Edge& b) {\n return a.c\ + \ < b.c;\n}\nostream& operator << (ostream& out, const Edge& e) {\n out <<\ + \ e.u << \" - \" << e.v << \" [\" << e.c << ']';\n return out;\n}\n// }}}\n" dependsOn: - DataStructure/DSU/DisjointSet.h isVerificationFile: false path: Graph/mst.h requiredBy: [] - timestamp: '2023-01-07 01:46:12+08:00' + timestamp: '2024-03-17 02:51:32+00:00' verificationStatus: LIBRARY_ALL_AC verifiedWith: + - Graph/tests/yosupo_mst.test.cpp - Graph/tests/aizu_grl_2_a_mst.test.cpp documentation_of: Graph/mst.h layout: document diff --git a/Graph/tests/aizu_grl_2_a_mst.test.cpp.md b/Graph/tests/aizu_grl_2_a_mst.test.cpp.md index 2d6ea90..c27c03e 100644 --- a/Graph/tests/aizu_grl_2_a_mst.test.cpp.md +++ b/Graph/tests/aizu_grl_2_a_mst.test.cpp.md @@ -58,19 +58,19 @@ data: \ lab[v] = u;\n return true;\n }\n\n bool same_component(int u, int\ \ v) {\n return getRoot(u) == getRoot(v);\n }\n\n int component_size(int\ \ u) {\n return -lab[getRoot(u)];\n }\n};\n// }}}\n#line 9 \"Graph/mst.h\"\ - \n\n// MST {{{\nusing ll = long long;\nstruct Edge {\n int u, v;\n ll c;\n\ - };\nbool operator < (const Edge& a, const Edge& b) {\n return a.c < b.c;\n\ - }\nostream& operator << (ostream& out, const Edge& e) {\n out << e.u << \"\ - \ - \" << e.v << \" [\" << e.c << ']';\n return out;\n}\nstd::pair>\ - \ mst(\n int n,\n std::vector edges) {\n std::sort(edges.begin(),\ - \ edges.end());\n\n DSU dsu(n + 1); // tolerate 1-based index\n ll total\ - \ = 0;\n vector tree;\n for (const auto& e : edges) {\n const\ - \ auto [u, v, c] = e;\n if (dsu.merge(u, v)) {\n total += c;\n\ + \n\n// MST {{{\nusing ll = long long;\ntemplate\nstd::pair> mst(\n int n,\n std::vector edges)\ + \ {\n std::sort(edges.begin(), edges.end());\n\n DSU dsu(n + 1); // tolerate\ + \ 1-based index\n ll total = 0;\n vector tree;\n for (const auto&\ + \ e : edges) {\n if (dsu.merge(e.u, e.v)) {\n total += e.c;\n\ \ tree.push_back(e);\n }\n }\n return {total, tree};\n\ - }\n// }}}\n#line 5 \"Graph/tests/aizu_grl_2_a_mst.test.cpp\"\n\nvoid solve() {\n\ - \ int n, m; cin >> n >> m;\n vector edges(m);\n for (auto& [u,\ - \ v, c] : edges) cin >> u >> v >> c;\n\n cout << mst(n, edges).first << endl;\n\ - }\n" + }\nstruct Edge {\n int u, v;\n ll c;\n};\nbool operator < (const Edge& a,\ + \ const Edge& b) {\n return a.c < b.c;\n}\nostream& operator << (ostream& out,\ + \ const Edge& e) {\n out << e.u << \" - \" << e.v << \" [\" << e.c << ']';\n\ + \ return out;\n}\n// }}}\n#line 5 \"Graph/tests/aizu_grl_2_a_mst.test.cpp\"\ + \n\nvoid solve() {\n int n, m; cin >> n >> m;\n vector edges(m);\n\ + \ for (auto& [u, v, c] : edges) cin >> u >> v >> c;\n\n cout << mst(n, edges).first\ + \ << endl;\n}\n" code: "#define PROBLEM \"https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_2_A\"\ \n\n#include \"../../template.h\"\n#include \"../mst.h\"\n\nvoid solve() {\n \ \ int n, m; cin >> n >> m;\n vector edges(m);\n for (auto& [u, v,\ @@ -83,7 +83,7 @@ data: isVerificationFile: true path: Graph/tests/aizu_grl_2_a_mst.test.cpp requiredBy: [] - timestamp: '2023-01-07 01:46:12+08:00' + timestamp: '2024-03-17 02:51:32+00:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: Graph/tests/aizu_grl_2_a_mst.test.cpp diff --git a/Graph/tests/yosupo_mst.test.cpp.md b/Graph/tests/yosupo_mst.test.cpp.md new file mode 100644 index 0000000..cb0dc96 --- /dev/null +++ b/Graph/tests/yosupo_mst.test.cpp.md @@ -0,0 +1,98 @@ +--- +data: + _extendedDependsOn: + - icon: ':heavy_check_mark:' + path: DataStructure/DSU/DisjointSet.h + title: DataStructure/DSU/DisjointSet.h + - icon: ':heavy_check_mark:' + path: Graph/mst.h + title: Graph/mst.h + - icon: ':heavy_check_mark:' + path: template.h + title: template.h + _extendedRequiredBy: [] + _extendedVerifiedWith: [] + _isVerificationFailed: false + _pathExtension: cpp + _verificationStatusIcon: ':heavy_check_mark:' + attributes: + '*NOT_SPECIAL_COMMENTS*': '' + PROBLEM: https://judge.yosupo.jp/problem/minimum_spanning_tree + links: + - https://judge.yosupo.jp/problem/minimum_spanning_tree + bundledCode: "#line 1 \"Graph/tests/yosupo_mst.test.cpp\"\n#define PROBLEM \"https://judge.yosupo.jp/problem/minimum_spanning_tree\"\ + \n\n#line 1 \"template.h\"\n#include \nusing namespace std;\n\n\ + #define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)\n#define FORD(i,a,b) for(int\ + \ i=(a),_b=(b); i>=_b; i--)\n#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)\n\ + #define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)\n\ + \n#define DEBUG(x) { cout << #x << \" = \"; cout << (x) << endl; }\n#define PR(a,n)\ + \ { cout << #a << \" = \"; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }\n#define\ + \ PR0(a,n) { cout << #a << \" = \"; REP(_,n) cout << a[_] << ' '; cout << endl;\ + \ }\n\n#define sqr(x) ((x) * (x))\n\n// For printing pair, container, etc.\n//\ + \ Copied from https://quangloc99.github.io/2021/07/30/my-CP-debugging-template.html\n\ + template ostream& operator << (ostream& out, const pair&\ + \ p) {\n return out << '(' << p.first << \", \" << p.second << ')';\n}\n\n\ + template()))>\ntypename enable_if::value, ostream&>::type\noperator << (ostream& out, const Con& con)\ + \ {\n out << '{';\n for (auto beg = con.begin(), it = beg; it != con.end();\ + \ it++) {\n out << (it == beg ? \"\" : \", \") << *it;\n }\n return\ + \ out << '}';\n}\ntemplate ostream& print_tuple_utils(ostream&\ + \ out, const T& tup) {\n if constexpr(i == tuple_size::value) return out\ + \ << \")\"; \n else return print_tuple_utils(out << (i ? \", \" :\ + \ \"(\") << get(tup), tup); \n}\ntemplate ostream& operator <<\ + \ (ostream& out, const tuple& t) {\n return print_tuple_utils<0, tuple>(out,\ + \ t);\n}\n\nmt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());\n\ + long long get_rand(long long r) {\n return uniform_int_distribution\ + \ (0, r-1)(rng);\n}\n\ntemplate\nvector read_vector(int n) {\n\ + \ vector res(n);\n for (int& x : res) cin >> x;\n return res;\n}\n\ + \nvoid solve();\n\nint main() {\n ios::sync_with_stdio(0); cin.tie(0);\n \ + \ solve();\n return 0;\n}\n#line 1 \"Graph/mst.h\"\n// MST. 0-based index\n\ + //\n// Returns:\n// {mst cost, edges in mst}\n//\n// If graph is not connected,\ + \ returns forest (number of edges will be < n-1)\n\n#line 1 \"DataStructure/DSU/DisjointSet.h\"\ + \n// DisjointSet {{{\nstruct DSU {\n vector lab;\n\n DSU(int n) : lab(n+1,\ + \ -1) {}\n\n int getRoot(int u) {\n if (lab[u] < 0) return u;\n \ + \ return lab[u] = getRoot(lab[u]);\n }\n\n bool merge(int u, int v) {\n\ + \ u = getRoot(u); v = getRoot(v);\n if (u == v) return false;\n\ + \ if (lab[u] > lab[v]) swap(u, v);\n lab[u] += lab[v];\n \ + \ lab[v] = u;\n return true;\n }\n\n bool same_component(int u, int\ + \ v) {\n return getRoot(u) == getRoot(v);\n }\n\n int component_size(int\ + \ u) {\n return -lab[getRoot(u)];\n }\n};\n// }}}\n#line 9 \"Graph/mst.h\"\ + \n\n// MST {{{\nusing ll = long long;\ntemplate\nstd::pair> mst(\n int n,\n std::vector edges)\ + \ {\n std::sort(edges.begin(), edges.end());\n\n DSU dsu(n + 1); // tolerate\ + \ 1-based index\n ll total = 0;\n vector tree;\n for (const auto&\ + \ e : edges) {\n if (dsu.merge(e.u, e.v)) {\n total += e.c;\n\ + \ tree.push_back(e);\n }\n }\n return {total, tree};\n\ + }\nstruct Edge {\n int u, v;\n ll c;\n};\nbool operator < (const Edge& a,\ + \ const Edge& b) {\n return a.c < b.c;\n}\nostream& operator << (ostream& out,\ + \ const Edge& e) {\n out << e.u << \" - \" << e.v << \" [\" << e.c << ']';\n\ + \ return out;\n}\n// }}}\n#line 5 \"Graph/tests/yosupo_mst.test.cpp\"\n\nstruct\ + \ E : Edge {\n int id;\n};\n\nvoid solve() {\n int n, m; cin >> n >> m;\n\ + \ vector edges(m);\n REP(i,m) {\n auto& e = edges[i];\n \ + \ cin >> e.u >> e.v >> e.c;\n e.id = i;\n }\n auto g = mst(n,\ + \ edges);\n cout << g.first << '\\n';\n for (auto& e : g.second) cout <<\ + \ e.id << ' ';\n cout << '\\n';\n}\n" + code: "#define PROBLEM \"https://judge.yosupo.jp/problem/minimum_spanning_tree\"\ + \n\n#include \"../../template.h\"\n#include \"../mst.h\"\n\nstruct E : Edge {\n\ + \ int id;\n};\n\nvoid solve() {\n int n, m; cin >> n >> m;\n vector\ + \ edges(m);\n REP(i,m) {\n auto& e = edges[i];\n cin >> e.u >>\ + \ e.v >> e.c;\n e.id = i;\n }\n auto g = mst(n, edges);\n cout\ + \ << g.first << '\\n';\n for (auto& e : g.second) cout << e.id << ' ';\n \ + \ cout << '\\n';\n}\n" + dependsOn: + - template.h + - Graph/mst.h + - DataStructure/DSU/DisjointSet.h + isVerificationFile: true + path: Graph/tests/yosupo_mst.test.cpp + requiredBy: [] + timestamp: '2024-03-17 02:51:32+00:00' + verificationStatus: TEST_ACCEPTED + verifiedWith: [] +documentation_of: Graph/tests/yosupo_mst.test.cpp +layout: document +redirect_from: +- /verify/Graph/tests/yosupo_mst.test.cpp +- /verify/Graph/tests/yosupo_mst.test.cpp.html +title: Graph/tests/yosupo_mst.test.cpp +--- diff --git a/index.md b/index.md index 87bf949..d6a7380 100644 --- a/index.md +++ b/index.md @@ -934,6 +934,9 @@ data: - icon: ':heavy_check_mark:' path: Graph/tests/two_sat.test.cpp title: Graph/tests/two_sat.test.cpp + - icon: ':heavy_check_mark:' + path: Graph/tests/yosupo_mst.test.cpp + title: Graph/tests/yosupo_mst.test.cpp - name: Math/tests pages: - icon: ':heavy_check_mark:' diff --git a/template.h.md b/template.h.md index 463042d..7fe128d 100644 --- a/template.h.md +++ b/template.h.md @@ -189,6 +189,9 @@ data: - icon: ':heavy_check_mark:' path: Graph/tests/aizu_grl_5_a_tree_diameter.test.cpp title: Graph/tests/aizu_grl_5_a_tree_diameter.test.cpp + - icon: ':heavy_check_mark:' + path: Graph/tests/yosupo_mst.test.cpp + title: Graph/tests/yosupo_mst.test.cpp - icon: ':heavy_check_mark:' path: Math/tests/aizu_ntl_1_a_factorize.test.cpp title: Math/tests/aizu_ntl_1_a_factorize.test.cpp @@ -404,6 +407,7 @@ data: - DP/tests/aizu_alds1_5_d_count_inversions.test.cpp - Graph/tests/aizu_grl_4_a_strongly_connected_cycle_check.test.cpp - Graph/tests/aizu_grl_3_a_articulation_points.test.cpp + - Graph/tests/yosupo_mst.test.cpp - Graph/tests/aizu_grl_5_a_tree_diameter.test.cpp - Graph/tests/aizu_grl_2_a_mst.test.cpp - Graph/tests/aizu_grl_1_c_floyd.test.cpp