Submission #13473183


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

struct UnionFind {
    vector<int> par,rank,large;

    void init(int N){
        rank.assign(N,0);
        large.assign(N,1);
        par.resize(N);
        for(int i= 0; i < N; i++){
            par[i]=i;
        }
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if(rank[rx]<rank[ry]) {
            par[rx]=ry;
            large[ry]+=large[rx];
            large[rx]=0;
        }
        else {
            par[ry]=rx;
            large[rx]+=large[ry];
            large[ry]=0;
            if(rank[rx]==rank[ry])rank[x]++;
        }
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return large[root(x)];
    }
};

int main() {
  int N,M;
  cin>>N>>M;
  UnionFind tree;
  tree.init(N+M);
  for(int i = 0; i < N; i++){
    int K;
    cin>>K;
    for(int j = 0; j < K; j++){
      int l;
      cin>>l;
      tree.unite(l-1,M+i);
    }
  }
  bool ans = true;
  for(int i = M; i < N+M-1; i++){
    if(!tree.same(i,i+1)) ans=false;
  }
  if(ans)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Submission Info

Submission Time
Task C - Interpretation
User ohaini1123
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1715 Byte
Status
Exec Time 47 ms
Memory 2560 KB

Judge Result

Set Name Score / Max Score Test Cases
sample 0 / 0 sample-01.txt, sample-02.txt
dataset1 200 / 200 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 200 / 200 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 1 ms 256 KB
01-02.txt 1 ms 256 KB
01-03.txt 2 ms 256 KB
01-04.txt 2 ms 256 KB
01-05.txt 2 ms 256 KB
01-06.txt 2 ms 256 KB
01-07.txt 1 ms 256 KB
01-08.txt 2 ms 256 KB
01-09.txt 2 ms 256 KB
01-10.txt 2 ms 256 KB
02-01.txt 33 ms 1536 KB
02-02.txt 40 ms 1408 KB
02-03.txt 33 ms 896 KB
02-04.txt 43 ms 2048 KB
02-05.txt 40 ms 1280 KB
02-06.txt 43 ms 2048 KB
02-07.txt 42 ms 1408 KB
02-08.txt 33 ms 1408 KB
02-09.txt 47 ms 2560 KB
02-10.txt 38 ms 1408 KB
02-11.txt 38 ms 1408 KB
02-12.txt 39 ms 1408 KB
02-13.txt 37 ms 1408 KB
sample-01.txt 1 ms 256 KB
sample-02.txt 1 ms 256 KB