CODE FESTIVAL 2016 Final

Submission #5438753

Source codeソースコード

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
// #define DEBUGGING

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

struct UnionFind {
    V<ll> rank;
    V<ll> parent;

    UnionFind(ll N) : rank(N, 0), parent(N) {
        iota(parent.begin(), parent.end(), 0ll);
    }

    ll find(ll child) {
        return (child == parent[child] ? child : parent[child] = find(parent[child]));
    }

    void unit(ll x, ll y) {
        ll px = find(x);
        ll py = find(y);
        if(px == py) {
            return;
        }
        if(rank[px] < rank[py]) {
            swap(px, py);
        }
        parent[py] = px;
        rank[px] += (rank[px] == rank[py]);
    }

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

int main() {
    ll N, M;
    cin >> N >> M;
    UnionFind uf(N + M + 10);
    for(ll i = 0; i < N; i++) {
        ll k;
        cin >> k;
        while(k--) {
            ll l;
            cin >> l;
            l--;
            uf.unit(i, N + l);
        }
    }

    ll par = uf.find(0);
    for(ll i = 1; i < N; i++) {
        if(uf.find(i) == par) continue;
        cout << "NO\n";
        return 0;
    }
    cout << "YES\n";
    return 0;
}

Submission

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