Submission #2677

# Submission time Handle Problem Language Result Execution time Memory
2677 2013-07-30T14:47:16 Z gs13068 간선 파괴 (GA5_destroy) C++
100 / 100
1288 ms 34616 KB
#include<cstdio>
#include<vector>

#define BUCKET_SIZE 6

int s[300000];
int e[300000];

struct edge
{
int s;
int e;
} temp;

std::vector<edge> pre[5000];
std::vector<edge> suf[5000];
int parent[1000];
int height[1000];

inline int root(int x)
{
return parent[x]==x?x:parent[x]=root(parent[x]);
}

inline void combine(int a,int b)
{
a=root(a);
b=root(b);
if(height[a]<height[b])parent[a]=b;
else parent[b]=a;
if(height[a]==height[b])height[b]++;
}

int main()
{
int i,j,k,n,m,l,r,q;
scanf("%d%d",&n,&m);
for(i=0;i<m;i++)
{
scanf("%d%d",&s[i],&e[i]);
s[i]--;e[i]--;
}
for(i=0;i<n;i++)
{
parent[i]=i;
height[i]=0;
}
for(i=0;i<m;i++)
{
combine(s[i],e[i]);
if((i&((1<<BUCKET_SIZE)-1))==(1<<BUCKET_SIZE)-1)
{
for(j=0;j<n;j++)if(parent[j]!=j)
{
temp.s=j;
temp.e=parent[j];
pre[i>>BUCKET_SIZE].push_back(temp);
}
}
}
for(i=0;i<n;i++)
{
parent[i]=i;
height[i]=0;
}
for(i=m-1;i>=0;i--)
{
combine(s[i],e[i]);
if(!(i&((1<<BUCKET_SIZE)-1)))
{
for(j=0;j<n;j++)if(parent[j]!=j)
{
temp.s=j;
temp.e=parent[j];
suf[i>>BUCKET_SIZE].push_back(temp);
}
}
}
scanf("%d",&q);
for(i=0;i<q;i++)
{
scanf("%d%d",&l,&r);
l--;r--;
for(j=0;j<n;j++)
{
parent[j]=j;
height[j]=0;
}
j=(l>>BUCKET_SIZE)-1;
if(j>=0)for(k=0;k<pre[j].size();k++)combine(pre[j][k].s,pre[j][k].e);
for(k=(l>>BUCKET_SIZE)<<BUCKET_SIZE;k<l;k++)combine(s[k],e[k]);
j=(r>>BUCKET_SIZE)+1;
for(k=0;k<suf[j].size();k++)combine(suf[j][k].s,suf[j][k].e);
for(k=r+1;k<((r>>BUCKET_SIZE)+1)<<BUCKET_SIZE;k++)combine(s[k],e[k]);
k=0;
for(j=0;j<n;j++)if(parent[j]==j)k++;
printf("%d\n",k);
}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3796 KB Output is correct
2 Correct 0 ms 3796 KB Output is correct
3 Correct 0 ms 3796 KB Output is correct
4 Correct 0 ms 3796 KB Output is correct
5 Correct 0 ms 3796 KB Output is correct
6 Correct 0 ms 3796 KB Output is correct
7 Correct 0 ms 3796 KB Output is correct
8 Correct 0 ms 3796 KB Output is correct
9 Correct 0 ms 3796 KB Output is correct
10 Correct 0 ms 3796 KB Output is correct
11 Correct 0 ms 3796 KB Output is correct
12 Correct 0 ms 3796 KB Output is correct
13 Correct 0 ms 3796 KB Output is correct
14 Correct 0 ms 3796 KB Output is correct
15 Correct 0 ms 3796 KB Output is correct
16 Correct 0 ms 3796 KB Output is correct
17 Correct 0 ms 3796 KB Output is correct
18 Correct 0 ms 3796 KB Output is correct
19 Correct 0 ms 3796 KB Output is correct
20 Correct 0 ms 3796 KB Output is correct
21 Correct 0 ms 3796 KB Output is correct
22 Correct 0 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 5512 KB Output is correct
2 Correct 40 ms 5380 KB Output is correct
3 Correct 40 ms 5644 KB Output is correct
4 Correct 60 ms 10000 KB Output is correct
5 Correct 52 ms 10000 KB Output is correct
6 Correct 376 ms 9736 KB Output is correct
7 Correct 372 ms 9472 KB Output is correct
8 Correct 368 ms 9340 KB Output is correct
9 Correct 36 ms 3928 KB Output is correct
10 Correct 36 ms 3928 KB Output is correct
11 Correct 36 ms 3928 KB Output is correct
12 Correct 64 ms 10000 KB Output is correct
13 Correct 56 ms 10000 KB Output is correct
14 Correct 52 ms 10000 KB Output is correct
15 Correct 28 ms 3796 KB Output is correct
16 Correct 32 ms 3928 KB Output is correct
17 Correct 12 ms 3796 KB Output is correct
18 Correct 8 ms 3796 KB Output is correct
19 Correct 4 ms 3796 KB Output is correct
20 Correct 4 ms 3796 KB Output is correct
21 Correct 0 ms 3796 KB Output is correct
22 Correct 0 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1244 ms 16692 KB Output is correct
2 Correct 1236 ms 15732 KB Output is correct
3 Correct 1272 ms 34616 KB Output is correct
4 Correct 1288 ms 16564 KB Output is correct
5 Correct 1280 ms 11136 KB Output is correct
6 Correct 1280 ms 34616 KB Output is correct
7 Correct 1228 ms 10448 KB Output is correct
8 Correct 1272 ms 11136 KB Output is correct
9 Correct 1232 ms 4476 KB Output is correct
10 Correct 1272 ms 4472 KB Output is correct
11 Correct 1192 ms 10720 KB Output is correct
12 Correct 1248 ms 34616 KB Output is correct
13 Correct 1224 ms 21440 KB Output is correct
14 Correct 1192 ms 21436 KB Output is correct
15 Correct 1172 ms 4068 KB Output is correct
16 Correct 1092 ms 4068 KB Output is correct
17 Correct 580 ms 3796 KB Output is correct
18 Correct 544 ms 3796 KB Output is correct
19 Correct 156 ms 3796 KB Output is correct
20 Correct 208 ms 3796 KB Output is correct
21 Correct 88 ms 3796 KB Output is correct
22 Correct 92 ms 3796 KB Output is correct