CODE FESTIVAL 2016 Final

Submission #992595

Source codeソースコード

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef vector<int, int> VII;
typedef vector<int> VI;
typedef pair<int, int> PII;

const int MAX_N = 1e6 + 5;
int par[MAX_N];

void init(int n) {
  for (int i = 0; i < n ; i++) {
    par[i] = i;
  }
}

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

void merge(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  par[x] = y;
}

bool same(int x, int y) {
  return find(x) == find(y);
}

int main() {
  int N, M;
  cin >> N >> M;
  init(N);
  VI ps;
  for (int i = 0; i < M; i++) {
    ps.push_back(-1);
  }

  for (int i = 0; i < N; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int n;
      cin >> n;
      n--;
      if (ps[n] == -1) {
        ps[n] = i;
      }
      merge(ps[n], i);
    }
  }

  for (int i = 0; i < N-1; i++) {
    if (!same(i, i+1)) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;

  return 0;
}

Submission

Task問題 C - Interpretation
User nameユーザ名 almizaar
Created time投稿日時
Language言語 C++14 (Clang 3.8.0)
Status状態 AC
Score得点 400
Source lengthソースコード長 1105 Byte
File nameファイル名
Exec time実行時間 129 ms
Memory usageメモリ使用量 2680 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 8 ms 888 KB
01-02.txt AC 3 ms 256 KB
01-03.txt AC 4 ms 256 KB
01-04.txt AC 4 ms 256 KB
01-05.txt AC 4 ms 256 KB
01-06.txt AC 4 ms 256 KB
01-07.txt AC 3 ms 384 KB
01-08.txt AC 4 ms 256 KB
01-09.txt AC 4 ms 256 KB
01-10.txt AC 4 ms 256 KB
02-01.txt AC 86 ms 892 KB
02-02.txt AC 114 ms 640 KB
02-03.txt AC 89 ms 640 KB
02-04.txt AC 111 ms 1148 KB
02-05.txt AC 116 ms 640 KB
02-06.txt AC 111 ms 1148 KB
02-07.txt AC 119 ms 768 KB
02-08.txt AC 100 ms 1408 KB
02-09.txt AC 129 ms 2680 KB
02-10.txt AC 103 ms 1532 KB
02-11.txt AC 102 ms 1532 KB
02-12.txt AC 100 ms 896 KB
02-13.txt AC 102 ms 896 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 3 ms 256 KB