Submission #6318684
Source Code Expand
#include <bits/stdc++.h> #define REP(i,n) for(int i=0;i<n;i++) #define REPP(i,n) for(int i=1;i<=n;i++) const double PI = acos(-1); const double EPS = 1e-15; long long INF=(long long)1E17; #define i_7 (long long)(1E9+7) long mod(long a){ long long c=a%i_7; if(c>=0)return c; return c+i_7; } using namespace std; bool prime(int n){ if(n==1){ return false; }else if(n==2){ return true; }else{ for(int i=2;i<=sqrt(n);i++){ if(n%i==0){ return false; } } return true; } } long long gcd(long long a, long long b){ if(a<b){ swap(a,b); } if(a%b==0){ return b; }else{ return gcd(b,a%b); } } long long lcm(long long x, long long y){ return (x/gcd(x,y))*y; } class UnionFind { public: //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。 vector<int> Parent; //クラスを作るときは、Parentの値を全て-1にする。 //以下のようにすると全てバラバラの頂点として解釈できる。 UnionFind(int N) { Parent = vector<int>(N, -1); } //Aがどのグループに属しているか調べる int root(int A) { if (Parent[A] < 0) return A; return Parent[A] = root(Parent[A]); } //自分のいるグループの頂点数を調べる int size(int A) { return -Parent[root(A)];//先祖をrootで取っておきたい。 } //AとBをくっ付ける bool connect(int A, int B) { //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける A = root(A); B = root(B); if (A == B) { //すでにくっついてるからくっ付けない return false; } //大きい方(A)に小さいほう(B)をくっ付けたい //大小が逆だったらAとBをひっくり返す。 if (size(A) < size(B)) swap(A, B); //Aのサイズを更新する Parent[A] += Parent[B]; //Bの親をAに変更する Parent[B] = A; return true; } }; int main(){ int n,m; cin>>n>>m; UnionFind uni(n+m); int k,l; REP(i,n){ cin>>k; REP(j,k){ cin>>l; l--; uni.connect(k,l+n); } } bool flag = true; int root; REP(i,n){ if(i==0){ root = uni.root(0); }else{ if(root==uni.root(i)){ continue; }else{ flag = false; break; } } } if(flag){ cout<<"YES"<<endl; }else{ cout<<"NO"<<endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Interpretation |
User | ready_player074 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2776 Byte |
Status | WA |
Exec Time | 46 ms |
Memory | 1024 KB |
Judge Result
Set Name | sample | dataset1 | dataset2 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 200 | 0 / 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 | WA | 1 ms | 256 KB |
01-02.txt | WA | 1 ms | 256 KB |
01-03.txt | AC | 2 ms | 256 KB |
01-04.txt | WA | 1 ms | 256 KB |
01-05.txt | AC | 1 ms | 256 KB |
01-06.txt | WA | 1 ms | 256 KB |
01-07.txt | WA | 1 ms | 256 KB |
01-08.txt | AC | 1 ms | 256 KB |
01-09.txt | WA | 1 ms | 256 KB |
01-10.txt | WA | 2 ms | 256 KB |
02-01.txt | WA | 31 ms | 640 KB |
02-02.txt | AC | 38 ms | 640 KB |
02-03.txt | AC | 32 ms | 512 KB |
02-04.txt | WA | 40 ms | 896 KB |
02-05.txt | WA | 39 ms | 640 KB |
02-06.txt | AC | 40 ms | 896 KB |
02-07.txt | WA | 40 ms | 640 KB |
02-08.txt | AC | 32 ms | 640 KB |
02-09.txt | WA | 46 ms | 1024 KB |
02-10.txt | WA | 37 ms | 640 KB |
02-11.txt | AC | 37 ms | 640 KB |
02-12.txt | WA | 36 ms | 640 KB |
02-13.txt | AC | 36 ms | 640 KB |
sample-01.txt | WA | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |