File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
tests/library_checker_aizu_tests/dsu Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 11#pragma once
2+ // ! @code
3+ // ! dsu_weighted dsu(n);
4+ // ! dsu.join(u, v, w);
5+ // ! // we now know a[u] == a[v] +
6+ // ! wdflasndoasdinvoasdiinfasd
7+ // ! @endcode
8+ // ! @time O(n + q * \alpha(n))
9+ // ! @space O(n)
210struct dsu_weighted {
311 vi p;
412 vector<ll> d;
Original file line number Diff line number Diff line change 1+ #define PROBLEM \
2+ " https://onlinejudge.u-aizu.ac.jp/problems/DSL_1_B"
3+ #include " ../template.hpp"
4+ #include " ../../../library/dsu/dsu_weighted.hpp"
5+ #include " ../../../library/dsu/dsu.hpp"
6+ int main () {
7+ cin.tie (0 )->sync_with_stdio (0 );
8+ int n, q;
9+ cin >> n >> q;
10+ dsu_weighted dsu_w (n);
11+ DSU dsu (n);
12+ while (q--) {
13+ int type, u, v;
14+ cin >> type >> u >> v;
15+ if (type == 0 ) {
16+ assert (dsu.size (u) == dsu_w.size (u));
17+ assert (dsu.size (v) == dsu_w.size (v));
18+ int w;
19+ cin >> w;
20+ dsu_w.join (u, v, w);
21+ dsu.join (u, v);
22+ assert (dsu.size (u) == dsu_w.size (u));
23+ assert (dsu.size (v) == dsu_w.size (v));
24+ } else {
25+ assert (dsu.size (u) == dsu_w.size (u));
26+ assert (dsu.size (v) == dsu_w.size (v));
27+ ll curr_diff = dsu_w.diff (u, v);
28+ if (curr_diff == 1e18 ) cout << " ?\n " ;
29+ else cout << dsu_w.diff (u, v) << ' \n ' ;
30+ }
31+ }
32+ return 0 ;
33+ }
You can’t perform that action at this time.
0 commit comments