Submission #13213

#TimeUsernameProblemLanguageResultExecution timeMemory
13213dohyun0324간선 파괴 (GA5_destroy)C++98
100 / 100
1151 ms2264 KiB
#include<stdio.h> #include<string.h> using namespace std; int cnt,group[710],ran[710],a,b,n,m,k,x[150010],y[150010],arr[710],arr2[710],w,w2,sw; int up(int x) { if(x==group[x]) return x; return group[x]=up(group[x]); } void union_find(int x,int y,int i) { int p=up(x),q=up(y); if(p==q) return; if(ran[p]>ran[q]) group[q]=p; else if(ran[p]<ran[q]) group[p]=q; else group[p]=q, ran[q]++; if(sw==0) arr[++w]=i; if(sw==1) arr2[++w2]=i; if(sw==2) cnt++; } void query(int a,int b) { int i; sw=2; cnt=0; for(i=1;i<=w;i++) { if(arr[i]>=a) break; union_find(x[arr[i]],y[arr[i]],arr[i]); } for(i=1;i<=w2;i++) { if(arr2[i]<=b) break; union_find(x[arr2[i]],y[arr2[i]],arr2[i]); } printf("%d\n",n-cnt); } int main() { int i,j; scanf("%d %d",&n,&m); for(i=1;i<=n;i++) group[i]=i; for(i=1;i<=m;i++) { scanf("%d %d",&x[i],&y[i]); union_find(x[i],y[i],i); } for(i=1;i<=n;i++) group[i]=i; memset(ran,0,sizeof ran); sw=1; for(i=m;i>=1;i--) union_find(x[i],y[i],i); scanf("%d",&k); for(i=1;i<=k;i++) { for(j=1;j<=n;j++) group[j]=j; memset(ran,0,sizeof ran); scanf("%d %d",&a,&b); query(a,b); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...