Submission #7470535


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;
typedef vector<vl> v2;
typedef vector<v2> v3;
typedef vector<v3> v4;


const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

ll n,m;
unordered_map<ll,vl> mp;

class union_find {
private:
  vl *par;
  vl *rnk;
  vl *siz;
public:
  union_find (ll n){
    par = new vl(n);
    iota(par->begin(),par->end(),0);
    rnk = new vl(n,0);
    siz = new vl(n,1);
  }
  ll find(ll x){
    if(par->at(x) == x) return x;
    else return par->at(x) = find(par->at(x));
  }
  ll size(ll x){
    return siz->at(find(x));
  }
  void unite(ll x,ll y){
    x = find(x);y = find(y);
    if(x == y)return;
    if(rnk->at(x) < rnk->at(y)){
      par->at(x) = y;
      siz->at(y) += siz->at(x);
    }
    else {
      par->at(y) = x;
      siz->at(x) += siz->at(y);
      if(rnk->at(x) == rnk->at(y)) rnk->at(x)++;
    }
  }
  bool same(ll x,ll y){
    return find(x) == find(y);
  }
};

union_find uf(0);

int main(){
  cin >> n >> m;
  for(ll i = 1;i <= n;i++){
    ll k;
    cin >> k;
    for(ll j = 0;j < k;j++){
      ll l;
      cin >> l;
      mp[l].push_back(i);
    }
  }
  uf = union_find(n+1);
  for(auto x : mp){
    for(ll y : x.second){
      uf.unite(x.second[0],y);
    }
  }
  if(uf.size(1) == n) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Submission Info

Submission Time
Task C - Interpretation
User deoxy
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1737 Byte
Status AC
Exec Time 64 ms
Memory 6668 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 200 / 200 200 / 200
Status
AC × 2
AC × 12
AC × 27
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 384 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 64 ms 6668 KB
02-02.txt AC 44 ms 3712 KB
02-03.txt AC 51 ms 4748 KB
02-04.txt AC 61 ms 5772 KB
02-05.txt AC 53 ms 4352 KB
02-06.txt AC 60 ms 5772 KB
02-07.txt AC 55 ms 4608 KB
02-08.txt AC 35 ms 3932 KB
02-09.txt AC 48 ms 4340 KB
02-10.txt AC 48 ms 6532 KB
02-11.txt AC 48 ms 6532 KB
02-12.txt AC 48 ms 6028 KB
02-13.txt AC 48 ms 6028 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB