CODE FESTIVAL 2016 Final

Submission #6842761

Source codeソースコード

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

vector<int> p;

int find_root(int x) {
  if (p[x] != x) p[x] = find_root(p[x]);
  return p[x];
}

void unite(int x, int y) {
  int nx = find_root(x);
  int ny = find_root(y);
  if (nx == ny) return;
  else {
    if (nx > ny) p[nx] = ny;
    else p[ny] = nx;
  }
}

int main() {
  int n, m; cin >> n >> m;
  vector<vector<int>> a(n);
  vector<bool> check(m, false);
  rep(i, n) {
    int k; cin >> k;
    rep(j, k) {
      int l; cin >> l;
      l --;
      check[l] = true;
      a[i].push_back(l);
    }
  }

  p = vector<int>(m);
  rep(i, m) p[i] = i;
  rep(i, n) {
    for (int j = 1; j < a[i].size(); j ++) {
      unite(a[i][0], a[i][j]);
    }
  }

  int sum = 0;
  rep(i, m) {
    if (p[i] == i && check[i]) sum ++;
  }

  if (sum == 1) cout << "YES" << endl;
  else cout << "NO" << endl; 
}

Submission

Task問題 C - Interpretation
User nameユーザ名 okaryo
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 400
Source lengthソースコード長 1009 Byte
File nameファイル名
Exec time実行時間 53 ms
Memory usageメモリ使用量 6144 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,sample-01.txt,sample-02.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 1 ms 256 KB
01-02.txt AC 2 ms 256 KB
01-03.txt AC 2 ms 256 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 35 ms 1408 KB
02-02.txt AC 46 ms 5504 KB
02-03.txt AC 36 ms 1408 KB
02-04.txt AC 47 ms 3712 KB
02-05.txt AC 47 ms 4608 KB
02-06.txt AC 48 ms 3712 KB
02-07.txt AC 48 ms 5248 KB
02-08.txt AC 40 ms 5760 KB
02-09.txt AC 53 ms 6144 KB
02-10.txt AC 42 ms 3328 KB
02-11.txt AC 42 ms 3324 KB
02-12.txt AC 40 ms 3328 KB
02-13.txt AC 40 ms 3456 KB
sample-01.txt AC 2 ms 256 KB
sample-02.txt AC 1 ms 256 KB