11232022-03-04 10:22:26kidesoSportos nyaraláscpp14Wrong answer 2/40107ms29440 KiB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int n = 50000;
vector<int> p[n + 1], z[n + 1];
int pk[n + 1], zk[n + 1], ans[n + 1];
bool lp[n + 1], lz[n + 1];
int N, P, Z;

void szelp(int kp, int s) {
	queue<int> y;
	lp[kp] = true;
	pk[kp] = s;
	y.push(kp);

	while (!y.empty()) {
		int csp = y.front();
		y.pop();

		for (auto e : p[csp])
			if (!lp[e]) {
				lp[e] = true;
				pk[e] = s;
				y.push(e);
			}
	}
}
void szelz(int kp, int s) {
	queue<int> y;
	lz[kp] = true;
	zk[kp] = s;
	y.push(kp);

	while (!y.empty()) {
		int csp = y.front();
		y.pop();

		for (auto e : z[csp]) {
			if (!lz[e]) {
				lz[e] = true;
				zk[e] = s;
				y.push(e);
			}

			if (pk[e] * pk[csp] != 0){
				if (pk[e] == pk[csp]) ++ans[csp];
			}

		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	cin >> N >> P >> Z;

	for (int i = 1; i <= P; ++i) {
		int a, b;
		cin >> a >> b;
		p[a].push_back(b), p[b].push_back(a);
	}

	for (int i = 1; i <= Z; ++i) {
		int a, b;
		cin >> a >> b;
		z[a].push_back(b), z[b].push_back(a);
	}

	int ps = 1, zs = 1;
	for (int i = 1; i <= N; ++i) {
		if (!lp[i]) {
			szelp(i, ps);
			++ps;
		}
	}

	for (int i = 1; i <= N; ++i) {
		if (!lz[i]) {
			szelz(i, zs);
			++zs;
		}
	}

	for (int i = 1; i <= N; ++i)
		cout << ans[i] << ' ';

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base2/40
1Accepted0/04ms6532 KiB
2Wrong answer0/071ms15708 KiB
3Accepted1/14ms7936 KiB
4Wrong answer0/14ms7936 KiB
5Wrong answer0/14ms7940 KiB
6Accepted1/13ms7948 KiB
7Wrong answer0/13ms7952 KiB
8Wrong answer0/13ms7956 KiB
9Wrong answer0/14ms7960 KiB
10Wrong answer0/14ms8168 KiB
11Wrong answer0/24ms8212 KiB
12Wrong answer0/24ms8240 KiB
13Wrong answer0/28ms9072 KiB
14Wrong answer0/28ms9104 KiB
15Wrong answer0/227ms12468 KiB
16Wrong answer0/237ms14348 KiB
17Wrong answer0/343ms16116 KiB
18Wrong answer0/346ms17084 KiB
19Wrong answer0/250ms16848 KiB
20Wrong answer0/254ms20300 KiB
21Wrong answer0/264ms22152 KiB
22Wrong answer0/256ms22632 KiB
23Wrong answer0/3107ms26348 KiB
24Wrong answer0/3104ms29440 KiB