CODE FESTIVAL 2016 Final

Submission #11224000

Source codeソースコード

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

struct UnionFind{
    int num;
    vector<int> par,rank;
    UnionFind(int n):num(n),par(n),rank(n,1){
        iota(par.begin(),par.end(),0);
    }
    int root(int x){
        if (par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    bool merge(int x, int y){
        x=root(x),y=root(y);
        if (x==y) return false;
        if (rank[x]<rank[y]) swap(x,y);
        par[y]=x;
        rank[x]+=rank[y];
        --num;
        return true;
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    int size(int x){
        return rank[root(x)];
    }
    int count(){
        return num;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    UnionFind uf(N+M);
    for (int i=0;i<N;++i){
        int K; cin >> K;
        for (;K--;){
            int L; cin >> L;
            uf.merge(i,L-1+N);
        }
    }
    int p=uf.root(0),ok=1;
    for (int i=1;i<N;++i)
        if (uf.root(i)!=p) ok=0;
    cout << (ok?"YES":"NO") << '\n';
}

Submission

Task問題 C - Interpretation
User nameユーザ名 rniya
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 400
Source lengthソースコード長 1114 Byte
File nameファイル名
Exec time実行時間 16 ms
Memory usageメモリ使用量 1792 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 1 ms 256 KB
01-03.txt AC 1 ms 256 KB
01-04.txt AC 1 ms 256 KB
01-05.txt AC 1 ms 256 KB
01-06.txt AC 1 ms 256 KB
01-07.txt AC 1 ms 256 KB
01-08.txt AC 1 ms 256 KB
01-09.txt AC 1 ms 256 KB
01-10.txt AC 1 ms 256 KB
02-01.txt AC 12 ms 1024 KB
02-02.txt AC 14 ms 1024 KB
02-03.txt AC 12 ms 768 KB
02-04.txt AC 16 ms 1536 KB
02-05.txt AC 14 ms 1024 KB
02-06.txt AC 16 ms 1536 KB
02-07.txt AC 15 ms 1024 KB
02-08.txt AC 13 ms 1024 KB
02-09.txt AC 16 ms 1792 KB
02-10.txt AC 13 ms 1024 KB
02-11.txt AC 12 ms 1024 KB
02-12.txt AC 13 ms 1024 KB
02-13.txt AC 13 ms 1024 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB