Submission #707665

#TimeUsernameProblemLanguageResultExecution timeMemory
707665ThMinh_Bridges (APIO19_bridges)C++14
0 / 100
2360 ms7600 KiB
#include<bits/stdc++.h> #define forin(i,a,b) for(int i=a;i<=b;++i) using namespace std; const int N = 5e4 + 10; int n, m, p, s = 1e3; int vis[N << 1], ans[N << 1], par[N]; struct brg { int u, v, w; }; brg e[N << 1]; struct quest { int t, b, r, w, s, i; }; quest q[N << 1]; stack<pair<int, int>> rb; int root(int x) { if(par[x] < 0) return x; return root(par[x]); } void join(int u, int v, int task) { u = root(u); v = root(v); if(u == v) return; if(par[u] > par[v]) swap(u, v); if(task) { rb.push({u, par[u]}); rb.push({v, par[v]}); } par[u] += par[v]; par[v] = u; } void relife() { while(!rb.empty()) { int u, p; tie(u, p) = rb.top(); rb.pop(); par[u] = p; } } int main () { cin.tie(0)->sync_with_stdio(0); if(fopen("Task.inp","r")) { freopen("Task.inp","r",stdin); freopen("WA.out","w",stdout); } cin>>n>>m; forin(i,1,m) { int u, v, w; cin>>u>>v>>w; e[i] = {u, v, w}; } cin>>p; forin(i,1,p) { cin>>q[i].t; if(q[i].t == 1) cin>>q[i].b>>q[i].r; else cin>>q[i].s>>q[i].w; } forin(blk,0,s) { int f = blk * s + 1; int l = min(p, (blk + 1) * s); if(f > l) break; fill(par + 1, par + n + 1, -1); fill(vis + 1, vis + m + 1, 0); vector<brg> rem; vector<quest> emilia; forin(i,f,l) { if(q[i].t == 1) vis[q[i].b] = 1; else { quest aa = q[i]; aa.i = i; emilia.push_back(aa); } } forin(i,1,m) if(!vis[i]) rem.push_back(e[i]); sort(rem.begin(), rem.end(), [] (brg x, brg y) { return x.w > y.w; }); sort(emilia.begin(), emilia.end(), [] (quest x, quest y) { return x.w > y.w; }); int j = 0; for(auto Q : emilia) { int s = Q.s, w = Q.w, i = Q.i; while(j <= rem.size() - 1 && rem[j].w >= w) { join(rem[j].u, rem[j].v, 0); j++; } forin(o,f,l) if(q[o].t == 1) vis[q[o].b] = e[q[o].b].w; forin(o,f,i) if(q[o].t == 1) e[q[o].b].w = q[o].r; forin(o,f,l) if(q[o].t == 1 && e[q[o].b].w >= w){ join(e[q[o].b].u, e[q[o].b].v, 1); } forin(o,f,l) if(q[o].t == 1) e[q[o].b].w = vis[q[o].b]; s = root(s); ans[i] = abs(par[s]); relife(); } forin(i,f,l) if(q[i].t == 1) e[q[i].b].w = q[i].r; } forin(i,1,p) if(q[i].t == 2) cout<<ans[i]<<"\n"; }

Compilation message (stderr)

bridges.cpp: In function 'int main()':
bridges.cpp:80:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<brg>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |             while(j <= rem.size() - 1 && rem[j].w >= w) {
      |                   ~~^~~~~~~~~~~~~~~~~
bridges.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen("Task.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen("WA.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...