Submission #993164
Source Code Expand
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <queue> using namespace std; int par[10000]; int rank_[10000]; int find(int x){ if(par[x]==x){ return x; }else{ return par[x]=find(par[x]); } } void unite(int x, int y){ x=find(x); y=find(y); if(x==y)return; if(rank_[x]<rank_[y]){ par[x]=y; }else{ par[y]=x; if(rank_[x]==rank_[y]) rank_[x]++; } } bool exist[10000]; int main(){ int N,M; cin>>N>>M; for(int i=0;i<M;i++){ par[i]=i; rank_[i]=0; } for(int i=0;i<N;i++){ int Ki; cin>>Ki; vector<int> L(Ki); for(int j=0;j<Ki;j++){ cin>>L[j]; L[j]--; exist[L[j]]=true; } for(int j=1;j<Ki;j++){ unite(L[0],L[j]); } } int p; for(int i=0;i<M;i++){ if(exist[i]){ p=par[i]; break; } } for(int i=0;i<M;i++){ if(!exist[i]) continue; if(p!=par[i]){ cout<<"NO"<<endl; return 0; } } cout<<"YES"<<endl; }
Submission Info
Submission Time | |
---|---|
Task | A - Where's Snuke? |
User | conf |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1223 Byte |
Status | WA |
Exec Time | 3 ms |
Memory | 256 KB |
Judge Result
Set Name | sample | all | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 100 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt |
all | 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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | WA | 3 ms | 256 KB |
01-02.txt | WA | 3 ms | 256 KB |
01-03.txt | WA | 3 ms | 256 KB |
01-04.txt | WA | 3 ms | 256 KB |
01-05.txt | WA | 3 ms | 256 KB |
01-06.txt | WA | 3 ms | 256 KB |
01-07.txt | WA | 3 ms | 256 KB |
sample-01.txt | WA | 3 ms | 256 KB |
sample-02.txt | WA | 3 ms | 256 KB |