Submission #993497
Source Code Expand
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;
class UnionFindFixed{
vector<int> data;
public:
UnionFindFixed(int size) : data(size, -1) { }
bool unionSet(int x, int y) {
x = root(x); y = root(y);
if (x != y) {
if (data[y] < data[x]) swap(x, y);
data[x] += data[y]; data[y] = x;
}
return x != y;
}
bool findSet(int x, int y) {
return root(x) == root(y);
}
int root(int x) {
return data[x] < 0 ? x : data[x] = root(data[x]);
}
int size(int x) {
return -data[root(x)];
}
};
int main(){
int N,M; cin>>N>>M;
vector<vector<int>> L;
REP(i,N){
vector<int> t;
int K; cin>>K;
REP(j,K){
int tt; cin>>tt;
t.push_back(tt);
}
L.push_back(t);
}
UnionFindFixed inst(300010);
REP(i,N){
REP(j,L[i].size()){
inst.unionSet(i,L[i][j]+200000);
}
}
int root=inst.root(0);
REP(i,N){
if(inst.root(i)!=root){
cout<<"NO"<<endl;
return 0;
}
}
cout<<"YES"<<endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Interpretation |
User |
kosakkun |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
2078 Byte |
Status |
AC |
Exec Time |
68 ms |
Memory |
6832 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 |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
4 ms |
1408 KB |
01-02.txt |
AC |
4 ms |
1408 KB |
01-03.txt |
AC |
4 ms |
1408 KB |
01-04.txt |
AC |
5 ms |
1408 KB |
01-05.txt |
AC |
5 ms |
1408 KB |
01-06.txt |
AC |
4 ms |
1408 KB |
01-07.txt |
AC |
5 ms |
1408 KB |
01-08.txt |
AC |
5 ms |
1408 KB |
01-09.txt |
AC |
5 ms |
1408 KB |
01-10.txt |
AC |
5 ms |
1408 KB |
02-01.txt |
AC |
37 ms |
2048 KB |
02-02.txt |
AC |
60 ms |
6704 KB |
02-03.txt |
AC |
38 ms |
2236 KB |
02-04.txt |
AC |
54 ms |
4532 KB |
02-05.txt |
AC |
58 ms |
5808 KB |
02-06.txt |
AC |
55 ms |
4532 KB |
02-07.txt |
AC |
61 ms |
6320 KB |
02-08.txt |
AC |
52 ms |
6832 KB |
02-09.txt |
AC |
68 ms |
6832 KB |
02-10.txt |
AC |
49 ms |
4404 KB |
02-11.txt |
AC |
49 ms |
4404 KB |
02-12.txt |
AC |
48 ms |
4276 KB |
02-13.txt |
AC |
47 ms |
4276 KB |
sample-01.txt |
AC |
4 ms |
1408 KB |
sample-02.txt |
AC |
4 ms |
1408 KB |