Submission #992405
Source Code Expand
#include <vector>
#include <cstdio>
using namespace std;
class union_find{
int *parent,n;
public:
union_find(int _n){n=_n;parent=new int[n+1];for(int i=1;i<=n;i++)parent[i]=i;}
~union_find(){delete []parent;}
int root(int a){return parent[a]==a?a:(parent[a]=root(parent[a]));}
int unite(int a,int b){
int x=root(a),y=root(b);
if(x==y)return 0;
parent[x]=y;
return 1;
}
};
int main(){
int N,M;
scanf("%d%d",&N,&M);
union_find uf(M);
vector<int>v(M+1);
for(;N--;){
int n,x,y;
scanf("%d%d",&n,&x);
v[x]++;
n--;
for(;n--;){
scanf("%d",&y);
uf.unite(x,y);
v[y]++;
}
}
int root=-1;
for(int i=1;i<=M;i++){
if(v[i]){
if(root<0)root=uf.root(i);
else if(root!=uf.root(i)){puts("NO");return 0;}
}
}
puts("YES");
}
Submission Info
Submission Time |
|
Task |
C - Interpretation |
User |
leafmoon |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
797 Byte |
Status |
AC |
Exec Time |
18 ms |
Memory |
1152 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:19:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&N,&M);
^
./Main.cpp:24:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&x);
^
./Main.cpp:28:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&y);
^
Judge Result
Set Name |
sample |
dataset1 |
dataset2 |
Score / Max Score |
0 / 0 |
200 / 200 |
200 / 200 |
Status |
|
|
|
Set Name |
Test Cases |
sample |
sample-01.txt, sample-02.txt |
dataset1 |
sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt |
dataset2 |
sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
2 ms |
256 KB |
01-02.txt |
AC |
2 ms |
256 KB |
01-03.txt |
AC |
3 ms |
256 KB |
01-04.txt |
AC |
2 ms |
256 KB |
01-05.txt |
AC |
2 ms |
256 KB |
01-06.txt |
AC |
2 ms |
256 KB |
01-07.txt |
AC |
2 ms |
256 KB |
01-08.txt |
AC |
2 ms |
256 KB |
01-09.txt |
AC |
3 ms |
256 KB |
01-10.txt |
AC |
2 ms |
256 KB |
02-01.txt |
AC |
18 ms |
1024 KB |
02-02.txt |
AC |
15 ms |
256 KB |
02-03.txt |
AC |
17 ms |
640 KB |
02-04.txt |
AC |
18 ms |
1024 KB |
02-05.txt |
AC |
16 ms |
256 KB |
02-06.txt |
AC |
18 ms |
1024 KB |
02-07.txt |
AC |
16 ms |
256 KB |
02-08.txt |
AC |
14 ms |
256 KB |
02-09.txt |
AC |
17 ms |
1024 KB |
02-10.txt |
AC |
15 ms |
1024 KB |
02-11.txt |
AC |
15 ms |
1152 KB |
02-12.txt |
AC |
15 ms |
640 KB |
02-13.txt |
AC |
15 ms |
640 KB |
sample-01.txt |
AC |
2 ms |
256 KB |
sample-02.txt |
AC |
2 ms |
256 KB |