Submission #991943
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
struct UF{
int n;
//正だったらその頂点の親,負だったら根で連結成分の個数
vector<int> d;
UF() {}
UF(int N):n(N), d(N,-1){}
int root(int v){
if(d[v]<0) return v;
return d[v]=root(d[v]);
}
bool unite(int X,int Y){
X=root(X); Y=root(Y);
if(X==Y) return false;
if(size(X) < size(Y)) swap(X,Y);
d[X]+=d[Y];
d[Y]=X;
return true;
}
int size(int v){ return -d[root(v)]; }
bool same(int X,int Y){ return root(X)==root(Y); }
};
int main()
{
int n,m;
scanf(" %d %d", &n, &m);
UF uf(n+m);
rep(i,n)
{
int k;
scanf(" %d", &k);
rep(j,k)
{
int L;
scanf(" %d", &L);
--L;
uf.unite(i,n+L);
}
}
string ans="YES";
rep(i,n) if(!uf.same(0,i)) ans="NO";
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Interpretation |
User |
imulan |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
1278 Byte |
Status |
AC |
Exec Time |
21 ms |
Memory |
1024 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:37:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf(" %d %d", &n, &m);
^
./Main.cpp:44:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf(" %d", &k);
^
./Main.cpp:48:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf(" %d", &L);
^
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 |
3 ms |
256 KB |
01-02.txt |
AC |
3 ms |
256 KB |
01-03.txt |
AC |
3 ms |
256 KB |
01-04.txt |
AC |
3 ms |
256 KB |
01-05.txt |
AC |
3 ms |
256 KB |
01-06.txt |
AC |
3 ms |
256 KB |
01-07.txt |
AC |
3 ms |
256 KB |
01-08.txt |
AC |
3 ms |
256 KB |
01-09.txt |
AC |
3 ms |
256 KB |
01-10.txt |
AC |
3 ms |
256 KB |
02-01.txt |
AC |
14 ms |
640 KB |
02-02.txt |
AC |
19 ms |
640 KB |
02-03.txt |
AC |
14 ms |
512 KB |
02-04.txt |
AC |
19 ms |
896 KB |
02-05.txt |
AC |
19 ms |
640 KB |
02-06.txt |
AC |
19 ms |
896 KB |
02-07.txt |
AC |
20 ms |
640 KB |
02-08.txt |
AC |
20 ms |
640 KB |
02-09.txt |
AC |
21 ms |
1024 KB |
02-10.txt |
AC |
17 ms |
640 KB |
02-11.txt |
AC |
17 ms |
640 KB |
02-12.txt |
AC |
17 ms |
640 KB |
02-13.txt |
AC |
16 ms |
640 KB |
sample-01.txt |
AC |
3 ms |
256 KB |
sample-02.txt |
AC |
3 ms |
256 KB |