Submission #984364

#TimeUsernameProblemLanguageResultExecution timeMemory
984364saayan007Bridges (APIO19_bridges)C++17
13 / 100
282 ms524288 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 ans(int x) { return sz[find(x)]; } }; #warning constants according to subtask const int N = 1001; const int M = 1001; int n, m, q; int ed[M][3]; /* set<pair<int, int>> adj[N]; */ UFDS uf; void modify(int b, int r) { /* rep(j, 0, 1) adj[ed[b][j]].erase(mp(ed[b][1 - j], ed[b][2])); */ ed[b][2] = r; /* rep(j, 0, 1) adj[ed[b][j]].insert(mp(ed[b][1 - j], ed[b][2])); */ } void query(int s, int w) { uf.init(n + 1); rep(i, 1, m) { if(ed[i][2] < w) continue; uf.unite(ed[i][0], ed[i][1]); /* cout << ed[i][0] << ' ' << ed[i][1] << nl; */ } cout << uf.ans(s) << nl; /* cout << nl; */ } 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]; /* rep(j, 0, 1) adj[ed[i][j]].insert(mp(ed[i][1 - j], ed[i][2])); */ } 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; query(s, w); } } }

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 'void query(long long int, 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:66:5: note: in expansion of macro 'rep'
   66 |     rep(i, 1, m) {
      |     ^~~
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:80:5: note: in expansion of macro 'rep'
   80 |     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:81:9: note: in expansion of macro 'rep'
   81 |         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:86:5: note: in expansion of macro 'rep'
   86 |     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...