Submission #7954189
Source Code Expand
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;
struct UnionFind {
vector<ll> par;
UnionFind(ll n) : par(n, -1) { }
void init(ll n) { par.assign(n, -1); }
ll find(ll x) {
if (par[x] < 0) return x;
else return par[x] = find(par[x]);
}
bool same(ll x, ll y) {
return find(x) == find(y);
}
bool unite(ll x, ll y) {
x = find(x); y = find(y);
if (x == y) return false;
if (par[x] > par[y]) swap(x, y);
par[x] += par[y];
par[y] = x;
return true;
}
ll size(ll x) {
return -par[find(x)];
}
void print(ll x){
rep(i,x){
cout<<par[i]<<endl;
}
return ;
}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
ll n,m,v[100010];
cin>>n>>m;
vll l[100010];
UnionFind uf(n);
vector<pll> G;
rep(i,n){
cin>>v[i];
rep(j,v[i]){
ll b;
cin>>b;
l[b].push_back(i);
}
}
rep2(i,1,m+1){
if(l[i].size()<=1) continue;
rep(j,l[i].size()){
if(j==l[i].size()-1) continue;
uf.unite(l[i][j],l[i][j+1]);
}
}
if(uf.size(0)==n) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Interpretation |
User |
t6is |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
2451 Byte |
Status |
AC |
Exec Time |
23 ms |
Memory |
5504 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 |
2 ms |
2560 KB |
01-02.txt |
AC |
2 ms |
3328 KB |
01-03.txt |
AC |
3 ms |
2688 KB |
01-04.txt |
AC |
2 ms |
3328 KB |
01-05.txt |
AC |
3 ms |
2688 KB |
01-06.txt |
AC |
2 ms |
3072 KB |
01-07.txt |
AC |
3 ms |
2688 KB |
01-08.txt |
AC |
3 ms |
2688 KB |
01-09.txt |
AC |
2 ms |
3072 KB |
01-10.txt |
AC |
2 ms |
2688 KB |
02-01.txt |
AC |
19 ms |
4864 KB |
02-02.txt |
AC |
16 ms |
5248 KB |
02-03.txt |
AC |
19 ms |
4992 KB |
02-04.txt |
AC |
23 ms |
5248 KB |
02-05.txt |
AC |
21 ms |
5504 KB |
02-06.txt |
AC |
23 ms |
5120 KB |
02-07.txt |
AC |
21 ms |
5376 KB |
02-08.txt |
AC |
15 ms |
5064 KB |
02-09.txt |
AC |
17 ms |
5368 KB |
02-10.txt |
AC |
16 ms |
5372 KB |
02-11.txt |
AC |
16 ms |
5372 KB |
02-12.txt |
AC |
16 ms |
5504 KB |
02-13.txt |
AC |
17 ms |
5248 KB |
sample-01.txt |
AC |
2 ms |
2560 KB |
sample-02.txt |
AC |
2 ms |
3200 KB |