Submission #1775524


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;
    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);
        }
    }
    map<int, int>Mp;
    int key=v[0][0];
    rep(i,v[0].size())uni.unite(key,v[0][i]);
    rep(i,n){
        bool in=false;
        rep(j,v[i].size()){
            if(uni.same(key,v[i][j])){
                in=true;
                break;
            }
        }
        if(in)rep(j,v[i].size())uni.unite(key,v[i][j]);
        else Mp[v[i][0]]++;
    }
    bool ans=true;
    rep(i,n){
        bool in=false;
        rep(j,v[i].size()){
            if(uni.same(key,v[i][j])){
                in=true;
                break;
            }
        }
        if(in)rep(j,v[i].size())uni.unite(key,v[i][j]);
        else ans=false;
    }
    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 2394 Byte
Status WA
Exec Time 59 ms
Memory 6912 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 0 / 200 0 / 200
Status
AC × 2
AC × 9
WA × 3
AC × 20
WA × 7
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 1 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 WA 2 ms 256 KB
01-10.txt AC 2 ms 256 KB
02-01.txt AC 35 ms 2304 KB
02-02.txt AC 51 ms 5632 KB
02-03.txt AC 37 ms 1920 KB
02-04.txt WA 59 ms 6016 KB
02-05.txt WA 57 ms 5248 KB
02-06.txt AC 59 ms 6016 KB
02-07.txt WA 59 ms 5760 KB
02-08.txt AC 41 ms 5760 KB
02-09.txt AC 55 ms 6912 KB
02-10.txt AC 42 ms 3712 KB
02-11.txt AC 42 ms 3708 KB
02-12.txt WA 41 ms 3840 KB
02-13.txt AC 42 ms 3840 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB