11222022-03-04 10:19:44kidesoSportos nyaraláscpp14Time limit exceeded 16/401.092s21356 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);
			}
	}
}

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;
		}

		if (!lz[i]) {
			szelz(i, zs);
			++zs;
		}
	}

	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= N; ++j)
			if (i != j && pk[i] * pk[j] != 0 && zk[i] * zk[j] != 0) {
				if (pk[i] == pk[j] && zk[i] == zk[j]) ++ans[i];
			}

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

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base16/40
1Accepted0/04ms6532 KiB
2Time limit exceeded0/01.003s8512 KiB
3Accepted1/13ms8008 KiB
4Accepted1/13ms8020 KiB
5Accepted1/13ms8016 KiB
6Accepted1/13ms8020 KiB
7Accepted1/13ms8028 KiB
8Accepted1/13ms8032 KiB
9Accepted1/13ms8052 KiB
10Accepted1/14ms8124 KiB
11Accepted2/26ms8188 KiB
12Accepted2/24ms8272 KiB
13Accepted2/212ms9192 KiB
14Accepted2/210ms9160 KiB
15Time limit exceeded0/21.006s7456 KiB
16Time limit exceeded0/21.092s8652 KiB
17Time limit exceeded0/31.09s9928 KiB
18Time limit exceeded0/31.031s10736 KiB
19Time limit exceeded0/21.044s11108 KiB
20Time limit exceeded0/21.08s13452 KiB
21Time limit exceeded0/21.049s15076 KiB
22Time limit exceeded0/21.065s15836 KiB
23Time limit exceeded0/31.085s18624 KiB
24Time limit exceeded0/31.092s21356 KiB