Submission #1775634


Source Code Expand

#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
class unionfind {
    vector<int> par, rank, size_;//速度ではなくメモリ効率を考えるならrankのかわりにsizeを使う
public:
    unionfind(int n) :par(n), rank(n), size_(n, 1) {
        iota(all(par), 0);
    }
    int find(int x) {
        if (par[x] == x)return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y])swap(x, y);
        par[y] = x;
        size_[x] += size_[y];
        if (rank[x] == rank[y])rank[x]++;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return size_[find(x)];
    }
};
signed main(){
    int n,p; cin>>n>>p;
    map<int,int>Mp;
    vector<vector<int>>v(n,vector<int>());
    unionfind uni(p+1);
    rep(i,n){
        int k; cin>>k;
        rep(j,k){
            int temp; cin>>temp;
            v[i].push_back(temp);
            Mp[temp]++;
        }
    }
    rep(i,n){
        int key=v[i][0];
        rep(j,v[i].size()){
            uni.unite(key,v[i][j]);
        }
    }
    bool ans=false;
    if(uni.size(1)==Mp.size())ans=true;
    //cout<<uni.size(1)<<endl;
    cout<<(ans?"YES":"NO")<<endl;
}

Submission Info

Submission Time
Task C - Interpretation
User yebityon
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1998 Byte
Status WA
Exec Time 74 ms
Memory 6912 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 × 24
WA × 3
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 256 KB
01-03.txt AC 2 ms 384 KB
01-04.txt AC 2 ms 256 KB
01-05.txt AC 2 ms 256 KB
01-06.txt WA 2 ms 256 KB
01-07.txt WA 2 ms 256 KB
01-08.txt AC 2 ms 256 KB
01-09.txt AC 2 ms 256 KB
01-10.txt AC 2 ms 256 KB
02-01.txt WA 71 ms 5120 KB
02-02.txt AC 53 ms 5632 KB
02-03.txt AC 61 ms 3840 KB
02-04.txt AC 74 ms 6528 KB
02-05.txt AC 62 ms 5248 KB
02-06.txt AC 73 ms 6528 KB
02-07.txt AC 64 ms 5760 KB
02-08.txt AC 44 ms 5760 KB
02-09.txt AC 54 ms 6912 KB
02-10.txt AC 51 ms 6140 KB
02-11.txt AC 52 ms 6140 KB
02-12.txt AC 56 ms 5888 KB
02-13.txt AC 56 ms 5888 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB