32142023-02-22 17:07:33zsomborSportos nyaraláscpp17Elfogadva 40/40207ms20048 KiB
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int n, m1, m2, a, b, cnt;
vector <vector <int>> g1(5e4 + 1);
vector <vector <int>> g2(5e4 + 1);
vector <int> k1(5e4 + 1, 0);
vector <int> k2(5e4 + 1, 0);
map <pair <int, int>, int> m;

void dfs1(int x) {
    if (k1[x]) return;
    k1[x] = cnt;
    for (int i : g1[x]) dfs1(i);
}

void dfs2(int x) {
    if (k2[x]) return;
    k2[x] = cnt;
    for (int i : g2[x]) dfs2(i);
}

int main()
{
    cin >> n >> m1 >> m2;
    for (int i = 0; i < m1; i++) {
        cin >> a >> b;
        g1[a].push_back(b);
        g1[b].push_back(a);
    }
    for (int i = 0; i < m2; i++) {
        cin >> a >> b;
        g2[a].push_back(b);
        g2[b].push_back(a);
    }
    cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (k1[i]) continue;
        cnt++;
        dfs1(i);
    }
    cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (k2[i]) continue;
        cnt++;
        dfs2(i);
    }
    for (int i = 1; i <= n; i++) m[{k1[i], k2[i]}]++;
    for (int i = 1; i <= n; i++) cout << m[{k1[i], k2[i]}] - 1 << " ";
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/04ms7316 KiB
2Elfogadva0/0131ms18860 KiB
3Elfogadva1/14ms7832 KiB
4Elfogadva1/14ms8048 KiB
5Elfogadva1/14ms8260 KiB
6Elfogadva1/14ms8472 KiB
7Elfogadva1/14ms8692 KiB
8Elfogadva1/14ms8644 KiB
9Elfogadva1/14ms8644 KiB
10Elfogadva1/17ms8900 KiB
11Elfogadva2/27ms9144 KiB
12Elfogadva2/28ms9224 KiB
13Elfogadva2/219ms10016 KiB
14Elfogadva2/216ms9988 KiB
15Elfogadva2/252ms14804 KiB
16Elfogadva2/271ms17004 KiB
17Elfogadva3/390ms18816 KiB
18Elfogadva3/392ms18816 KiB
19Elfogadva2/282ms14764 KiB
20Elfogadva2/2107ms16336 KiB
21Elfogadva2/2126ms17676 KiB
22Elfogadva2/2111ms18492 KiB
23Elfogadva3/3151ms18816 KiB
24Elfogadva3/3207ms20048 KiB