Submission #991793


Source Code Expand

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

struct union_find {
	vector<int> v;
	union_find(int n) : v(n, -1) {}
	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int main() {
	int N, M; cin >> N >> M;
	vector<vector<int> > a(N);
	rep(i, N) {
		int K; scanf("%d", &K);
		while (K--) {
			int x; scanf("%d", &x);
			a[i].pb(x);
		}
	}
	vector<int> A;
	rep(i, N) for (int x: a[i]) A.pb(x);
	sort(A.begin(), A.end());
	A.erase(unique(A.begin(), A.end()), A.end());
	M = A.size();
	rep(i, N) for (int& x: a[i]) x = lower_bound(A.begin(), A.end(), x) - A.begin();
	union_find uf(N + M);
	rep(i, N) for (int x: a[i]) uf.unite(i, N + x);
	cout << (uf.size(0) == N + M ? "YES" : "NO") << endl;
}

Submission Info

Submission Time
Task C - Interpretation
User sugim48
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1707 Byte
Status AC
Exec Time 45 ms
Memory 6648 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:55:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   int K; scanf("%d", &K);
                         ^
./Main.cpp:57:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
    int x; scanf("%d", &x);
                          ^

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 200 / 200 200 / 200
Status
AC × 2
AC × 12
AC × 25
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 3 ms 256 KB
01-02.txt AC 3 ms 256 KB
01-03.txt AC 3 ms 256 KB
01-04.txt AC 3 ms 256 KB
01-05.txt AC 3 ms 384 KB
01-06.txt AC 3 ms 256 KB
01-07.txt AC 3 ms 256 KB
01-08.txt AC 3 ms 256 KB
01-09.txt AC 3 ms 256 KB
01-10.txt AC 3 ms 256 KB
02-01.txt AC 34 ms 1784 KB
02-02.txt AC 41 ms 6392 KB
02-03.txt AC 35 ms 1792 KB
02-04.txt AC 44 ms 4220 KB
02-05.txt AC 44 ms 5496 KB
02-06.txt AC 44 ms 4220 KB
02-07.txt AC 45 ms 6140 KB
02-08.txt AC 33 ms 6648 KB
02-09.txt AC 34 ms 6648 KB
02-10.txt AC 31 ms 4092 KB
02-11.txt AC 31 ms 4216 KB
02-12.txt AC 34 ms 4088 KB
02-13.txt AC 33 ms 4088 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 3 ms 256 KB