Submission #5933121


Source Code Expand

#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

struct UnionFind{
    vl par;
    vl rank;
    map<ll, ll> size;
    UnionFind(ll N) : par(N, 0), rank(N, 0){
        for(int i = 0; i < N; i++){
            par[i] = i; size[i] = 1;
        }
    }
    
    ll root(ll x){
        if(par[x] == x) return x;
        else{
            par[x] = root(par[x]); // compression
            return par[x];
        }
    }
    
    void unite(ll x, ll y){
        ll rx = root(x); ll ry = root(y);
        if(rx == ry) return;
        if(rank[rx] < rank[ry]) swap(rx, ry);
        if(rank[rx] == rank[ry]) ++rank[rx];
        par[ry] = rx;
        if(rx != ry) size[rx] = size[rx] + size[ry];
        else{
            size[rx] = max(size[rx], size[ry]);
        }
    }
    
    ll get_size(ll x){
        return size[root(x)];
    }
    
    bool same(ll x, ll y){
        return root(x) == root(y);
    }
};




int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    const ll offset = 100;
    ll N, M; cin >> N >> M;
    auto uf = UnionFind(N+M+offset);
    REP(i, N){
        ll K; cin >> K;
        REP(j, K){
            ll l; cin >> l; uf.unite(i, offset+l);
        }
    }
    bool ok = true;
    REP(i, N){
        if(!uf.same(0ll, i)){
            ok = false; break;
        }
    }
    
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}

Submission Info

Submission Time
Task C - Interpretation
User k_k_hiroki
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3487 Byte
Status WA
Exec Time 144 ms
Memory 15872 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 0 / 200 0 / 200
Status
AC × 2
AC × 10
WA × 2
AC × 22
WA × 5
Set Name Test Cases
sample sample-01.txt, sample-02.txt
dataset1 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 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
Case Name Status Exec Time Memory
01-01.txt AC 1 ms 256 KB
01-02.txt AC 2 ms 384 KB
01-03.txt AC 2 ms 384 KB
01-04.txt AC 2 ms 384 KB
01-05.txt WA 2 ms 384 KB
01-06.txt AC 2 ms 384 KB
01-07.txt AC 2 ms 384 KB
01-08.txt WA 2 ms 384 KB
01-09.txt AC 2 ms 384 KB
01-10.txt AC 2 ms 384 KB
02-01.txt AC 103 ms 8448 KB
02-02.txt WA 89 ms 7936 KB
02-03.txt AC 58 ms 4992 KB
02-04.txt AC 141 ms 12416 KB
02-05.txt AC 77 ms 7296 KB
02-06.txt AC 141 ms 12416 KB
02-07.txt AC 88 ms 8064 KB
02-08.txt AC 87 ms 8064 KB
02-09.txt AC 144 ms 15872 KB
02-10.txt AC 64 ms 8064 KB
02-11.txt WA 63 ms 8064 KB
02-12.txt AC 71 ms 8064 KB
02-13.txt WA 70 ms 8064 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB