제출 #707673

#제출 시각아이디문제언어결과실행 시간메모리
707673ThMinh_다리 (APIO19_bridges)C++14
100 / 100
2175 ms10720 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; forin(i,f,l) if(q[i].t == 1) vis[q[i].b] = e[q[i].b].w; for(auto Q : emilia) { int s = Q.s, w = Q.w, i = Q.i; while(!rem.empty() && rem.back().w >= w) { join(rem.back().u, rem.back().v, 0); rem.pop_back(); } 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"; }

컴파일 시 표준 에러 (stderr) 메시지

bridges.cpp: In function 'int main()':
bridges.cpp:77:13: warning: unused variable 'j' [-Wunused-variable]
   77 |         int j = 0;
      |             ^
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...