This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
struct Edge{int a,b;};
Edge inner(int a,int b)
{Edge r={a,b};return r;}
int ufind(int k, int *T)
{
if (T[k] == k) return k;
return T[k] = ufind(T[k], T);
}
int main()
{
int V,E,Q;
scanf("%d%d",&V,&E);
Edge G[50010];
int u,v;
for (int i=1; i<=E; i++) {
scanf("%d%d",&u,&v);
G[i] = inner(u,v);
}
scanf("%d",&Q);
while (Q--)
{
int T[510]={0}, a,b;
for (int i=1; i<=V; i++)
T[i] = i;
scanf("%d%d",&a,&b);
for (int i=1; i<=E; i++) {
if (a<=i && i<=b) continue;
int x = ufind(G[i].a, T);
int y = ufind(G[i].b, T);
T[x] = y;
}
for (int i=1; i<=V; i++)
ufind(i,T);
int C[800]={0}, ret=0;
for (int i=1; i<=V; i++)
ret += (C[T[i]]++)==0;
printf("%d\n",ret);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |