CODE FESTIVAL 2016 Final

Submission #992583

Source codeソースコード

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

struct UnionFind {
  vector<int> data;
  UnionFind(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)];
  }
};

#define int long long
#define range(i,x,y) i=(x);i<(y);i++
#define rep(i,n) for(int i=0,i##_len=n;i<i##_len;i++)
#define all(x) begin(x),end(x)
#define lim(x,r,l) (r<=x&&x<l)
typedef long long ll;
typedef long double ld;

signed main(){
  int n, m; cin >> n >> m;
  UnionFind uf(n);
  vector<vector<int>> merged(m, vector<int>());

  rep(i,n){
    int k; cin >> k;
    rep(j, k){
      int l; cin >> l;
      merged[l-1].push_back(i);
    }
  }

  rep(l, m){
    for(int i = 0; i < (signed) merged[l].size() - 1ll; i++){
      uf.unionSet(merged[l][i], merged[l][i+1]);
    }
  }

  if(uf.size(0) == n){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Submission

Task問題 C - Interpretation
User nameユーザ名 046_wass80
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 400
Source lengthソースコード長 1247 Byte
File nameファイル名
Exec time実行時間 53 ms
Memory usageメモリ使用量 4736 KB

Test case

Set

Set name Score得点 / Max score Cases
sample - 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 2 ms 256 KB
01-02.txt AC 3 ms 256 KB
01-03.txt AC 3 ms 256 KB
01-04.txt AC 3 ms 256 KB
01-05.txt AC 3 ms 256 KB
01-06.txt AC 3 ms 256 KB
01-07.txt AC 3 ms 256 KB
01-08.txt AC 3 ms 256 KB
01-09.txt AC 3 ms 256 KB
01-10.txt AC 3 ms 256 KB
02-01.txt AC 44 ms 4736 KB
02-02.txt AC 42 ms 1792 KB
02-03.txt AC 43 ms 3200 KB
02-04.txt AC 53 ms 4480 KB
02-05.txt AC 47 ms 2176 KB
02-06.txt AC 52 ms 4480 KB
02-07.txt AC 48 ms 2304 KB
02-08.txt AC 35 ms 1488 KB
02-09.txt AC 51 ms 4088 KB
02-10.txt AC 43 ms 3708 KB
02-11.txt AC 43 ms 3708 KB
02-12.txt AC 43 ms 3584 KB
02-13.txt AC 43 ms 3456 KB
sample-01.txt AC 2 ms 256 KB
sample-02.txt AC 2 ms 256 KB