Submission #7418269


Source Code Expand

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
using D = pair<double, double>;
const int mod2 = 998244353;
const int mod = (int)1e9 + 7, inf = (int)1e16;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] *= fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	int ans= fact[n] * modpow(fact[n - r], mod - 2) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int>factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

P operator+(const P& a, const P& b) {
	return P(a.first + b.first, a.second + b.second);
}
P operator-(const P& a, const P& b) {
	return P(a.first - b.first, a.second - b.second);
}

class unionfind {
private:
	int par[200010], rankth[200010], sizeth[200020];
public:
	void init(int n) {
		rep(i, n) {
			par[i] = i;
			rankth[i] = 0;
			sizeth[i] = 1;
		}
	}
	int root(int x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

	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 (rankth[x] < rankth[y]) {
			par[x] = y;
			sizeth[y] += sizeth[x];
		}
		else {
			par[y] = x;
			if (rankth[x] == rankth[y]) rankth[x]++;
			sizeth[x] += sizeth[y];
		}
	}
};

int n, m, k, l;
unionfind uni;
vector<int>v[100010];
signed main() {
	scanf("%lld %lld", &n, &m);
	uni.init(n + m);
	rep(i, n) {
		scanf("%lld", &k);
		rep(j, k) {
			scanf("%lld", &l);
			v[i].push_back(l);
		}
	}
	rep(i, n) {
		for (int j : v[i]) {
			uni.unite(i, n + j - 1);
		}
	}
	rep(i, n - 1) {
		if (!uni.same(i, i + 1)) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
}

Submission Info

Submission Time
Task C - Interpretation
User Ebishu0309
Language C++14 (GCC 5.4.1)
Score 400
Code Size 3112 Byte
Status AC
Exec Time 28 ms
Memory 11520 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:136:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld", &n, &m);
                            ^
./Main.cpp:139:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &k);
                    ^
./Main.cpp:141:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld", &l);
                     ^

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 200 / 200 200 / 200
Status
AC × 2
AC × 12
AC × 27
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 3 ms 8448 KB
01-02.txt AC 3 ms 8448 KB
01-03.txt AC 4 ms 8448 KB
01-04.txt AC 4 ms 8448 KB
01-05.txt AC 4 ms 8448 KB
01-06.txt AC 4 ms 8448 KB
01-07.txt AC 4 ms 8448 KB
01-08.txt AC 3 ms 8448 KB
01-09.txt AC 4 ms 8576 KB
01-10.txt AC 4 ms 8448 KB
02-01.txt AC 17 ms 9600 KB
02-02.txt AC 25 ms 11520 KB
02-03.txt AC 18 ms 9600 KB
02-04.txt AC 25 ms 10368 KB
02-05.txt AC 25 ms 11008 KB
02-06.txt AC 26 ms 10368 KB
02-07.txt AC 26 ms 11264 KB
02-08.txt AC 26 ms 11520 KB
02-09.txt AC 28 ms 11520 KB
02-10.txt AC 21 ms 10364 KB
02-11.txt AC 21 ms 10360 KB
02-12.txt AC 20 ms 10368 KB
02-13.txt AC 20 ms 10368 KB
sample-01.txt AC 3 ms 8448 KB
sample-02.txt AC 3 ms 8448 KB