제출 #146614

#제출 시각아이디문제언어결과실행 시간메모리
146614Bodo171다리 (APIO19_bridges)C++14
27 / 100
3043 ms23748 KiB
#include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <map> #include <cassert> using namespace std; const int nmax=100005; const int buck=1000; struct event { int tip,id,c; }ev,evs[nmax+2*buck],niu[nmax+2*buck]; bool comp(event unu,event doi) { if(unu.c==doi.c) return unu.tip>doi.tip; return unu.c<doi.c; } vector<int> spec,norm,mods; vector<int> ad[nmax]; map<int,int> act; int tt[nmax],rg[nmax],mic[nmax],mare[nmax],a[nmax],b[nmax],w[nmax],tip[nmax],wh[nmax],cost[nmax],ap[nmax],ans[nmax],ini[nmax],viz[nmax],ps[2*nmax]; int ops,n,m,q,i,nr,j,sum,lim; int finds(int x) { int y=x,aux; while(x!=tt[x]) x=tt[x]; while(y!=x) { aux=tt[y]; tt[y]=x; y=aux; } return x; } void unite(int A,int B) { if(A==B) return; if(rg[A]<rg[B]) swap(A,B); tt[B]=A;rg[A]+=rg[B]; } void add(int x,int y) { ad[x].push_back(y); ad[y].push_back(x); } void res(int x) { ad[x].resize(0); viz[x]=0; } void dfs(int x) { viz[x]=1;sum+=rg[x]; for(int it=0;it<ad[x].size();it++) if(!viz[ad[x][it]]) dfs(ad[x][it]); } void mysort() { for(i=1;i<=nr;i++) ps[evs[i].c]++; for(i=1;i<=lim;i++) ps[i]+=ps[i-1]; for(i=1;i<=nr;i++) niu[++ps[evs[i].c-1]]=evs[i]; for(i=0;i<=lim;i++) ps[i]=0; } int main() { //freopen("data.in","r",stdin); ios_base::sync_with_stdio(false); cin>>n>>m; for(i=1;i<=m;i++) { cin>>a[i]>>b[i]>>w[i]; norm.push_back(w[i]); } cin>>q; for(i=1;i<=q;i++) { cin>>tip[i]>>wh[i]>>cost[i]; norm.push_back(cost[i]); } sort(norm.begin(),norm.end()); norm.erase(unique(norm.begin(),norm.end()),norm.end()); lim=norm.size(); for(i=0;i<norm.size();i++) act[norm[i]]=i+1; for(i=1;i<=m;i++) w[i]=act[w[i]]; for(i=1;i<=q;i++) cost[i]=act[cost[i]]; for(int bg=1;bg<=q;bg+=buck) { nr=0; ops=0; spec.clear();mods.clear(); for(i=1;i<=n;i++) tt[i]=i,rg[i]=1; for(i=bg;i<min(bg+buck,q+1);i++) { if(tip[i]==1) { spec.push_back(wh[i]); ap[wh[i]]=1; ini[wh[i]]=w[wh[i]]; mods.push_back(i); } else { evs[++nr]={1,i,cost[i]}; } } for(i=1;i<=m;i++) if(!ap[i]) evs[++nr]={0,i,w[i]}; mysort(); for(i=nr;i>=1;i--) { ev=niu[i]; if(ev.tip==0) unite(finds(a[ev.id]),finds(b[ev.id])); else { int ind=ev.id; for(j=0; j<mods.size()&&mods[j]<=ind; j++) w[wh[mods[j]]]=cost[mods[j]]; for(j=0; j<spec.size(); j++) if(w[spec[j]]>=ev.c) add(finds(a[spec[j]]),finds(b[spec[j]])); sum=0; dfs(finds(wh[ind])); ans[ind]=sum; res(finds(wh[ind])); for(j=0; j<spec.size(); j++) { res(finds(a[spec[j]])); res(finds(b[spec[j]])); w[spec[j]]=ini[spec[j]]; } } } for(i=bg;i<min(bg+buck,q+1);i++) if(tip[i]==1) w[wh[i]]=cost[i]; for(i=0;i<spec.size();i++) ap[spec[i]]=0; } for(i=1;i<=q;i++) if(tip[i]==2) cout<<ans[i]<<'\n'; return 0; }

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

bridges.cpp: In function 'void dfs(int)':
bridges.cpp:56:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int it=0;it<ad[x].size();it++)
                  ~~^~~~~~~~~~~~~
bridges.cpp: In function 'int main()':
bridges.cpp:90:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<norm.size();i++)
             ~^~~~~~~~~~~~
bridges.cpp:129:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(j=0; j<mods.size()&&mods[j]<=ind; j++)
                          ~^~~~~~~~~~~~
bridges.cpp:131:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(j=0; j<spec.size(); j++)
                          ~^~~~~~~~~~~~
bridges.cpp:138:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(j=0; j<spec.size(); j++)
                          ~^~~~~~~~~~~~
bridges.cpp:149:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<spec.size();i++)
                 ~^~~~~~~~~~~~
#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...