Submission #196956

#TimeUsernameProblemLanguageResultExecution timeMemory
196956AkashiBridges (APIO19_bridges)C++14
0 / 100
3048 ms9012 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5e4 + 5; const int M = 1e5 + 5; const int bucket_size = 250; struct edges{ int x, y, w, p, w2, p1, p2; bool operator < (const edges &aux)const{ if(w != aux.w) return w > aux.w; return p < aux.p; } }; struct query{ int x, w, p; bool operator < (const query &aux)const{ if(w != aux.w) return w > aux.w; return p < aux.p; } }; edges a[M], e[M], b[bucket_size + 5]; query Q[bucket_size + 5]; int n, m, q; bool uz[M], f[M]; int SZ[N], TT[N]; int tip[M], ans[M]; vector <int> v[N]; inline int find(int x){ int R = x; while(R != TT[R]) R = TT[R]; while(x != R){ int aux = TT[x]; TT[x] = R; x = aux; } return R; } inline void unite(int x, int y){ if(x == y) return ; if(SZ[x] > SZ[y]) SZ[x] += SZ[y], TT[y] = x; else SZ[y] += SZ[x], TT[x] = y; } bool viz[N]; int dfs(int nod){ int ans = SZ[nod]; viz[nod] = 1; for(auto it : v[nod]){ if(viz[it]) continue ; ans += dfs(it); } return ans; } void bdfs(int nod){ viz[nod] = 0; for(auto it : v[nod]) if(viz[it]) bdfs(it); } int main() { // freopen("1.in", "r", stdin); scanf("%d%d", &n, &m); for(int i = 1; i <= m ; ++i){ scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].w); a[i].p = i; e[i] = a[i]; } scanf("%d", &q); int x, y, w; for(int i = 1; i <= q ; i += bucket_size){ memset(uz, 0, sizeof(uz)); sort(a + 1, a + m + 1); for(int i = 1; i <= n ; ++i) TT[i] = i, SZ[i] = 1; int j = min(q, i + bucket_size - 1), nr = 0, k = 0; for(int t = i; t <= j ; ++t){ scanf("%d%d%d", &tip[t], &x, &w); if(tip[t] == 1){ b[++k] = {e[x].x, e[x].y, w, t, e[x].w, 0, bucket_size}; if(e[x].p2){ b[e[x].p2].p2 = t - 1; b[k].p1 = e[x].p2 + 1; } uz[x] = 1; e[x].w = w; e[x].p2 = k; } else Q[++nr] = {x, w, t}; } sort(Q + 1, Q + nr + 1); j = 1; for(int i = 1; i <= nr ; ++i){ while(j <= m && Q[i].w <= a[j].w){ if(!uz[a[j].p]) unite(find(a[j].x), find(a[j].y)); ++j; } for(int t = 1; t <= k ; ++t){ if(b[t].p1 <= Q[i].p && Q[i].p <= b[t].p2) if((b[t].p > Q[i].p && b[t].w2 >= Q[i].w) || (b[t].p < Q[i].p && b[t].w >= Q[i].w)){ x = find(b[t].x); y = find(b[t].y); if(x != y){ v[x].push_back(y); v[y].push_back(x); } } } ans[Q[i].p] = dfs(find(Q[i].x)); bdfs(find(Q[i].x)); for(int t = 1; t <= k ; ++t){ x = find(b[t].x); y = find(b[t].y); v[x].clear(); v[y].clear(); } } for(int i = 1; i <= m ; ++i){ a[i].w = e[a[i].p].w; e[i].p2 = 0; } } for(int i = 1; i <= q ; ++i) if(tip[i] == 2) printf("%d\n", ans[i]); return 0; }

Compilation message (stderr)

bridges.cpp: In function 'int main()':
bridges.cpp:68:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
bridges.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].w);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:76:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &q);
     ~~~~~^~~~~~~~~~
bridges.cpp:86:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d%d", &tip[t], &x, &w);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...