Submission #1069349
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
int n,k,l;
vector<int>e[maxn];
vector<int>e2[maxn];
int f[maxn];
int ft[maxn];
int ft2[maxn];
int ans[maxn];
vector<int>in,inf;
int num;
int t;
void dfs(int now)
{
f[now]=t;
inf.push_back(now);
int i,j,len=e[now].size();
for(i=0;i<len;++i)
{
int v=e[now][i];
if(!f[v])
dfs(v);
}
}
void dfs2(int now)
{
if(f[now]!=t||ft2[now]==1)
{
return;
}
ft2[now]=1;
in.push_back(now);
num++;
int i,j,len=e2[now].size();
for(i=0;i<len;++i)
{
int v=e2[now][i];
if(!ft2[v])
dfs2(v);
}
}
int main()
{
int i,j;
scanf("%d%d%d",&n,&k,&l);
for(i=0;i<k;++i)
{
int x,y;
scanf("%d%d",&x,&y);
e[x].push_back(y);
e[y].push_back(x);
}
for(i=0;i<l;++i)
{
int x,y;
scanf("%d%d",&x,&y);
e2[x].push_back(y);
e2[y].push_back(x);
}
for(i=1;i<=n;++i)
{
if(!f[i])
{
t++;
if(!inf.empty())
inf.clear();
dfs(i);
int len1=inf.size();
for(j=0;j<len1;++j)
{
if(!in.empty())
in.clear();
num=0;
dfs2(inf[j]);
int len=in.size();
for(int p=0;p<len;++p)
ans[in[p]]=num;
}
}
}
printf("%d",ans[1]);
for(i=2;i<=n;++i)
{
printf(" %d",ans[i]);
}
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Connectivity |
User |
vjudge1 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1227 Byte |
Status |
RE |
Exec Time |
164 ms |
Memory |
8960 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:56:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&n,&k,&l);
^
./Main.cpp:60:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&x,&y);
^
./Main.cpp:68:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&x,&y);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
subtask0_0.txt, subtask0_1.txt, subtask0_2.txt |
All |
subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask1_0.txt, subtask1_1.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_2.txt, subtask1_3.txt, subtask1_4.txt, subtask1_5.txt, subtask1_6.txt, subtask1_7.txt, subtask1_8.txt, subtask1_9.txt |
Case Name |
Status |
Exec Time |
Memory |
subtask0_0.txt |
AC |
8 ms |
4992 KB |
subtask0_1.txt |
AC |
8 ms |
4992 KB |
subtask0_2.txt |
AC |
8 ms |
4992 KB |
subtask1_0.txt |
AC |
47 ms |
7552 KB |
subtask1_1.txt |
RE |
164 ms |
8960 KB |
subtask1_10.txt |
AC |
49 ms |
7808 KB |
subtask1_11.txt |
RE |
164 ms |
8832 KB |
subtask1_12.txt |
RE |
119 ms |
4864 KB |
subtask1_13.txt |
RE |
120 ms |
4864 KB |
subtask1_14.txt |
RE |
121 ms |
4864 KB |
subtask1_2.txt |
RE |
120 ms |
4864 KB |
subtask1_3.txt |
RE |
118 ms |
4864 KB |
subtask1_4.txt |
RE |
120 ms |
4864 KB |
subtask1_5.txt |
AC |
50 ms |
7808 KB |
subtask1_6.txt |
RE |
163 ms |
8704 KB |
subtask1_7.txt |
RE |
118 ms |
4864 KB |
subtask1_8.txt |
RE |
118 ms |
4864 KB |
subtask1_9.txt |
RE |
118 ms |
4864 KB |