Submission #992009


Source Code Expand

#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;

class UFT {
  vector<int> parent;
  vector<int> rank; //木の高さ
  vector<int> size;
public:
  UFT(int n){
    parent = vector<int>(n);
    rank = vector<int>(n,0);
    size = vector<int>(n,1);
    for(int i = 0; i < n; i++)
      parent[i] = i;
  }
  int find_root(int x){
    if ( parent[x] == x ) return x;
    return parent[x] = find_root( parent[x] );
  }
  void unite(int x, int y){
    int u = find_root(x);
    int v = find_root(y);
    if ( u == v ) return;
    if ( rank[u] < rank[v] ){
      parent[u] = v;
      size[v] += size[u];
    }else{
      parent[v] = u;
      size[u] += size[v];
      if ( rank[u] == rank[v] ) rank[x]++;
    }
  }
  bool is_same ( int x, int y ){
    return find_root(x) == find_root(y);
  }
  int size_of ( int x ){
    return size[ find_root(x) ];
  }
};

int N, M;
int K[100000];
set<int> L;
vector<int> l[100000];
int main(){
  cin >> N >> M;
  UFT uft(M);
  REP(i,N){
    cin >> K[i];
    REP(j,K[i]){
      int t;
      cin >> t;
      t--;
      l[i].push_back( t );
      L.insert( t );
      if( j > 0 ){
	uft.unite( l[i][0], l[i][j] );
      }
    }
  }
  if( uft.size_of( l[0][0] ) == L.size() ){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Submission Info

Submission Time
Task C - Interpretation
User sndtkrh
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1375 Byte
Status AC
Exec Time 80 ms
Memory 7808 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 200 / 200 200 / 200
Status
AC × 2
AC × 12
AC × 25
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 5 ms 2560 KB
01-02.txt AC 6 ms 2688 KB
01-03.txt AC 6 ms 2688 KB
01-04.txt AC 6 ms 2688 KB
01-05.txt AC 6 ms 2688 KB
01-06.txt AC 6 ms 2688 KB
01-07.txt AC 6 ms 2688 KB
01-08.txt AC 6 ms 2688 KB
01-09.txt AC 6 ms 2688 KB
01-10.txt AC 6 ms 2688 KB
02-01.txt AC 71 ms 7424 KB
02-02.txt AC 58 ms 6016 KB
02-03.txt AC 68 ms 5888 KB
02-04.txt AC 80 ms 7808 KB
02-05.txt AC 68 ms 6016 KB
02-06.txt AC 80 ms 7808 KB
02-07.txt AC 70 ms 6400 KB
02-08.txt AC 44 ms 6144 KB
02-09.txt AC 59 ms 7296 KB
02-10.txt AC 57 ms 7420 KB
02-11.txt AC 58 ms 7420 KB
02-12.txt AC 62 ms 7296 KB
02-13.txt AC 62 ms 7296 KB
sample-01.txt AC 5 ms 2560 KB
sample-02.txt AC 5 ms 2560 KB