Submission #992783


Source Code Expand

#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);

template<class T> inline T sqr(T x) {return x*x;}

class UnionFind {
    struct UFNode {
        int par;
        int rank;
    };
    vector<UFNode> nodes;
public:
    UnionFind(int n): nodes(n) {
        for (int i = 0; i < n; i++) {
            nodes[i].par = i;
            nodes[i].rank = 0;
        }
    };
    int root(int x) {
        return nodes[x].par == x ? x : nodes[x].par = root(nodes[x].par);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (nodes[x].rank < nodes[y].rank) {
            nodes[x].par = y;
        } else {
            nodes[y].par = x;
            if (nodes[x].rank == nodes[y].rank) nodes[x].rank++;
        }
    }
    //~UnionFind() {cout << nodes.size() << endl;}
};

bool ary[1001][1001];
bool b[1001][1001];

int main() {
	int n, m;
	cin >> n >> m;
	UnionFind u(n);
	int k, in;
	REP(i,0,1000) REP(j,0,1000) ary[i][j] = false; 
	REP(i,0,n) {
		cin >> k;
		REP(j,0,k) {
			cin >> in;
			ary[i][in] = true;
		}
	}
	REP(i,0,n) {
		REP(j,i+1,n) {
			if (u.same(i,j)) continue;
			//cout << i << "," << j << endl;
			REP(k,0,m+1) {
				if (ary[i][k] && ary[j][k]) {
					u.unite(i,j);
					//cout << i << "," << j << "," << k << endl;
					break;
				}
			}
		}
	} 

	REP(i,0,n) {
		REP(j,i+1,n) {
			if (u.same(i,j)) continue;
			cout << "NO" << endl;
			return 0;
		}
	} 
	cout << "YES" << endl;
	
	return 0;
}

Submission Info

Submission Time
Task C - Interpretation
User unsre
Language C++14 (GCC 5.4.1)
Score 200
Code Size 2717 Byte
Status RE
Exec Time 362 ms
Memory 2048 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 200 / 200 0 / 200
Status
AC × 2
AC × 12
AC × 12
RE × 13
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
Case Name Status Exec Time Memory
01-01.txt AC 4 ms 1408 KB
01-02.txt AC 4 ms 1280 KB
01-03.txt AC 362 ms 1408 KB
01-04.txt AC 7 ms 1280 KB
01-05.txt AC 30 ms 1280 KB
01-06.txt AC 90 ms 1280 KB
01-07.txt AC 27 ms 1280 KB
01-08.txt AC 91 ms 1280 KB
01-09.txt AC 63 ms 1280 KB
01-10.txt AC 7 ms 1280 KB
02-01.txt RE 119 ms 1280 KB
02-02.txt RE 115 ms 1920 KB
02-03.txt RE 119 ms 1280 KB
02-04.txt RE 115 ms 1664 KB
02-05.txt RE 115 ms 1792 KB
02-06.txt RE 117 ms 1664 KB
02-07.txt RE 118 ms 1920 KB
02-08.txt RE 116 ms 2048 KB
02-09.txt RE 117 ms 2048 KB
02-10.txt RE 116 ms 1664 KB
02-11.txt RE 119 ms 1664 KB
02-12.txt RE 116 ms 1664 KB
02-13.txt RE 119 ms 1664 KB
sample-01.txt AC 4 ms 1280 KB
sample-02.txt AC 4 ms 1280 KB