11212022-03-04 08:49:23kidesoSportos nyaraláscpp14Time limit exceeded 16/401.093s16192 KiB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

vector<vector<int> > p, z;
vector<int> pk, zk, ans;
vector<bool> lp, lz;
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;

	p.resize(N + 1), z.resize(N + 1);
	pk.resize(N + 1), zk.resize(N + 1), ans.resize(N + 1);
    lz.resize(N+1,false), lp.resize(N+1,false);

	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/02ms1756 KiB
2Time limit exceeded0/01.08s8468 KiB
3Accepted1/11ms3252 KiB
4Accepted1/12ms3256 KiB
5Accepted1/11ms3260 KiB
6Accepted1/11ms3272 KiB
7Accepted1/11ms3276 KiB
8Accepted1/11ms3280 KiB
9Accepted1/12ms3300 KiB
10Accepted1/12ms3456 KiB
11Accepted2/24ms3584 KiB
12Accepted2/24ms3604 KiB
13Accepted2/210ms4600 KiB
14Accepted2/29ms4488 KiB
15Time limit exceeded0/21.07s6452 KiB
16Time limit exceeded0/21.093s8176 KiB
17Time limit exceeded0/31.072s10004 KiB
18Time limit exceeded0/31.07s10632 KiB
19Time limit exceeded0/21.072s10212 KiB
20Time limit exceeded0/21.085s13208 KiB
21Time limit exceeded0/21.093s14960 KiB
22Time limit exceeded0/21.093s14892 KiB
23Time limit exceeded0/31.09s15808 KiB
24Time limit exceeded0/31.072s16192 KiB