Submission #3907507
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) #define abs(a) max((a),-(a)) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define repe(i,n) rep(i,(n)+1) #define per(i,n) for(int i=(int)(n)-1;i>=0;i--) #define pere(i,n) rep(i,(n)+1) #define all(x) (x).begin(),(x).end() #define SP <<" "<< #define RET return 0 #define MOD 1000000007 #define INF 1000000000000000000 typedef long long LL; typedef long double LD; vector<int> uf; int root(int x){ if(x==uf[x]) return x; else return uf[x]=root(uf[x]); } void uni(int x,int y){ x=root(x); y=root(y); if(x!=y) uf[x]=y; } int main(){ int n,m; cin >> n >> m; uf=vector<int>(n); for(int i=0;i<n;i++){ uf[i]=i; } vector<list<int>> l(m); int k,ll; for(int i=0;i<n;i++){ cin >> k; for(int j=0;j<k;j++){ cin >> ll; l[ll-1].push_back(i); } } int rr; for(int i=0;i<m;i++){ rr=l[i].front(); for(auto it:l[i]){ uni(rr,it); } } int r=root(0); for(int i=0;i<n;i++){ if(root(i)!=r){ cout << "NO" << endl; return 0; } } cout << "YES" << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Interpretation |
User | yamunaku |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1232 Byte |
Status | AC |
Exec Time | 56 ms |
Memory | 6912 KB |
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, sample-01.txt, sample-02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 1 ms | 256 KB |
01-02.txt | AC | 2 ms | 256 KB |
01-03.txt | AC | 2 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 | 2 ms | 256 KB |
01-10.txt | AC | 2 ms | 256 KB |
02-01.txt | AC | 42 ms | 4992 KB |
02-02.txt | AC | 54 ms | 3712 KB |
02-03.txt | AC | 42 ms | 4224 KB |
02-04.txt | AC | 52 ms | 5120 KB |
02-05.txt | AC | 52 ms | 3840 KB |
02-06.txt | AC | 51 ms | 5120 KB |
02-07.txt | AC | 56 ms | 3840 KB |
02-08.txt | AC | 40 ms | 4480 KB |
02-09.txt | AC | 55 ms | 6912 KB |
02-10.txt | AC | 47 ms | 4864 KB |
02-11.txt | AC | 45 ms | 4864 KB |
02-12.txt | AC | 45 ms | 4224 KB |
02-13.txt | AC | 44 ms | 4224 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |