Submission #974505

#TimeUsernameProblemLanguageResultExecution timeMemory
974505vivkostovBridges (APIO19_bridges)C++14
0 / 100
1577 ms24148 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); /*#ifdef ONLINE_JUDGE freopen("taxi.in", "r", stdin); freopen("taxi.out", "w", stdout); #endif */ } struct cell { int a,b,c,use,ti,old; }; bool cmp(cell a1,cell a2) { if(a1.c==a2.c)return a1.a>a2.a; return a1.c>a2.c; } int n,m,q,num[100005],b[100005],c[100005],lead[100005],sz[100005],otg[100005]; cell a[100005],f[100005],lis[100005]; stack<pair<int,int>>s; int get_lead(int a) { while(lead[a]!=a)a=lead[a]; return a; } void prec() { for(int i=1; i<=n; i++) { lead[i]=i; sz[i]=1; } } int bg; void add(int a,int b) { a=get_lead(a); b=get_lead(b); if(a==b)return; bg++; if(sz[a]<b[sz])swap(a,b); sz[a]+=sz[b]; lead[b]=a; pair<int,int>p; p.first=a; p.second=b; s.push(p); } void del() { int a=s.top().first,b=s.top().second; sz[a]-=sz[b]; lead[b]=s.top().second; s.pop(); } void read() { cin>>n>>m; for(int i=1; i<=m; i++) { cin>>a[i].a>>a[i].b>>a[i].c; } cin>>q; for(int i=1; i<=q; i++) { cin>>num[i]>>b[i]>>c[i]; } //cout<<endl; for(int i=1; i<=q; i+=500) { int br=0,br1=0; prec(); for(int j=i; j<=min(q,i+500); j++) { if(num[j]==1) { int o=a[b[j]].c; a[b[j]].use=1; a[b[j]].c=c[j]; br1++; lis[br1]=a[b[j]]; lis[br1].use=b[j]; lis[br1].ti=j; lis[br1].old=o; } else { br++; f[br].a=-j; f[br].b=b[j]; f[br].c=c[j]; f[br].ti=j; } } for(int j=1; j<=m; j++) { if(!a[j].use) { br++; f[br]=a[j]; } } sort(f+1,f+br+1,cmp); //cout<<endl; for(int j=1; j<=br1; j++) { //cout<<lis[j].a<<" "<<lis[j].b<<" "<<lis[j].c<<" "<<lis[j].use<<" "<<lis[j].ti<<" "<<lis[j].old<<endl; } for(int i=1; i<=n; i++) { //cout<<lead[i]<<" "<<sz[i]<<" "<<i<<endl; } //cout<<endl; for(int j=1; j<=br; j++) { if(f[j].a>0) { add(f[j].a,f[j].b); for(int i=1; i<=n; i++) { //cout<<lead[i]<<" "<<sz[i]<<" "<<i<<endl; } //cout<<endl; } else { bg=0; for(int h=1; h<=br1; h++) { if(lis[h].ti>f[j].ti&&lis[h].old>=f[j].c) { add(lis[h].a,lis[h].b); } if(lis[h].c>=f[j].c) { add(lis[h].a,lis[h].b); } } otg[-f[j].a]=sz[get_lead(f[j].b)]; //cout<<-f[j].a<<" "<<otg[-f[j].a]<<" "<<bg<<" "<<f[j].c<<" "<<f[j].ti<<endl; for(int z=1; z<=bg; z++)del(); } } for(int i=1; i<=n; i++) { a[i].use=0; lis[i].a=0; lis[i].b=0; lis[i].c=0; lis[i].use=0; lis[i].ti=0; lis[i].old=0; f[i].a=0; f[i].b=0; f[i].c=0; f[i].use=0; f[i].ti=0; } while(!s.empty())s.pop(); } //cout<<endl; for(int i=1; i<=q; i++) { if(num[i]==2)cout<<otg[i]<<endl; } } int main() { speed(); read(); return 0; }
#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...