Submission #984369

#TimeUsernameProblemLanguageResultExecution timeMemory
984369saayan007Bridges (APIO19_bridges)C++17
0 / 100
63 ms20660 KiB
#include "bits/stdc++.h" using namespace std; #define int long long #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i) #define repd(i, a, b) for(int (i) = (a); i >= (b); --i) #define em emplace #define eb emplace_back #define pi pair<int, int> #define fr first #define sc second #define mp make_pair const char nl = '\n'; const int mod = 1e9 + 7; const int inf = 1e17; struct UFDS { int n; vector<int> lnk, sz; void init(int N) { n = N; lnk.resize(n); sz.resize(n); rep(i, 0, n - 1) { lnk[i] = i; sz[i] = 1; } } int find(int x) { return (x == lnk[x] ? x : lnk[x] = find(lnk[x])); } void unite(int x, int y) { x = find(x); y = find(y); if(x == y) return; if(sz[x] < sz[y]) swap(x, y); lnk[y] = x; sz[x] += sz[y]; } int qry(int x) { return sz[find(x)]; } }; #warning constants according to subtask const int N = 5e4L + 10; const int M = 1e5L + 10; int n, m, q; int ed[M][3]; UFDS uf; using dt = array<int, 4>; dt A[2*M]; int ans[M]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; rep(i, 1, m) { rep(j, 0, 2) cin >> ed[i][j]; A[i][0] = ed[i][2]; A[i][1] = ed[i][0]; A[i][2] = ed[i][1]; A[i][3] = -1; } cin >> q; rep(i, 1, q) { int t; cin >> t; if(t == 1) { int b, r; cin >> b >> r; /* modify(b, r); */ } else { int s, w; cin >> s >> w; A[m + i][0] = w; A[m + i][1] = s; A[m + i][3] = i; /* query(s, w); */ } } sort(A + 1, A + m + q + 1, [&](dt &left, dt &right) { return mp(left[0], -left[3]) > mp(right[0], -right[3]); }); uf.init(n + 1); rep(i, 1, m + q) { if(A[i][3] < 0) { uf.unite(A[i][0], A[i][1]); } else { ans[A[i][3]] = uf.qry(A[i][1]); } } rep(i, 1, q) { cout << ans[i] << nl; } }

Compilation message (stderr)

bridges.cpp:50:2: warning: #warning constants according to subtask [-Wcpp]
   50 | #warning constants according to subtask
      |  ^~~~~~~
bridges.cpp: In member function 'void UFDS::init(long long int)':
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bridges.cpp:27:9: note: in expansion of macro 'rep'
   27 |         rep(i, 0, n - 1) {
      |         ^~~
bridges.cpp: In function 'int32_t main()':
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bridges.cpp:65:5: note: in expansion of macro 'rep'
   65 |     rep(i, 1, m) {
      |     ^~~
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bridges.cpp:66:9: note: in expansion of macro 'rep'
   66 |         rep(j, 0, 2) cin >> ed[i][j];
      |         ^~~
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bridges.cpp:75:5: note: in expansion of macro 'rep'
   75 |     rep(i, 1, q) {
      |     ^~~
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bridges.cpp:94:5: note: in expansion of macro 'rep'
   94 |     rep(i, 1, m + q) {
      |     ^~~
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bridges.cpp:102:5: note: in expansion of macro 'rep'
  102 |     rep(i, 1, q) {
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...