CODE FESTIVAL 2016 Final

Submission #991876

Source codeソースコード

#include <cstdio>
#include <vector>
#include <cstring>

using namespace std;

const int MAX_N = 111111;

struct uni {
  int p[MAX_N];
  uni(){init();}
  void init(){ memset(p,-1,sizeof(p)); }
  int root(int a) {
    return p[a]<0?a:(p[a]=root(p[a]));
  }
  bool find(int a,int b){ return root(a) == root(b); }
  bool merge(int a,int b) {
    a = root(a);
    b = root(b);
    if( a == b ) return false;
    p[a] += p[b];
    p[b] = a;
    return true;
  }
  int size(int a){ return -p[root(a)]; }
};

vector<int> g[111111];
uni u;

int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int k; scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int l; scanf("%d", &l); --l;
      g[l].push_back(i);
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 1; j < int(g[i].size()); j++) {
      u.merge(g[i][0], g[i][j]);
    }
  }
  
  bool ok = true;
  for (int i = 0; i < n; i++) {
    if (u.root(0) != u.root(i)) ok = false;
  }
  puts(ok ? "YES" : "NO");
  return 0;
}

Submission

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

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:33:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
^
./Main.cpp:35:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int k; scanf("%d", &k);
^
./Main.cpp:37:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int l; scanf("%d", &l); --l;
^

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 5 ms 3328 KB
01-02.txt AC 6 ms 3328 KB
01-03.txt AC 6 ms 3328 KB
01-04.txt AC 6 ms 3328 KB
01-05.txt AC 6 ms 3328 KB
01-06.txt AC 6 ms 3456 KB
01-07.txt AC 6 ms 3328 KB
01-08.txt AC 6 ms 3328 KB
01-09.txt AC 6 ms 3328 KB
01-10.txt AC 6 ms 3328 KB
02-01.txt AC 25 ms 5248 KB
02-02.txt AC 23 ms 3840 KB
02-03.txt AC 25 ms 4608 KB
02-04.txt AC 30 ms 4608 KB
02-05.txt AC 28 ms 4096 KB
02-06.txt AC 30 ms 4608 KB
02-07.txt AC 28 ms 4096 KB
02-08.txt AC 21 ms 3840 KB
02-09.txt AC 24 ms 3964 KB
02-10.txt AC 23 ms 5120 KB
02-11.txt AC 23 ms 5120 KB
02-12.txt AC 24 ms 4992 KB
02-13.txt AC 23 ms 4992 KB
sample-01.txt AC 5 ms 3328 KB
sample-02.txt AC 5 ms 3328 KB