48322023-03-31 13:09:33Error42Sportos nyaraláscpp17Elfogadva 40/40181ms22820 KiB
#include <array>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

void dfs(
    vector<vector<int>> const& graph,
    vector<bool>& done,
    vector<int>& component,
    int const cur,
    int const start
) {
    done[cur] = true;
    component[cur] = start;

    for (int const& neigh : graph[cur]) {
        if (done[neigh])
            continue;

        dfs(graph, done, component, neigh, start);
    }
}

int main() {
    array<int, 2> edge_count;

    int n;
    cin >> n >> edge_count[0] >> edge_count[1];

    vector graph(2, vector(n, vector<int>()));

    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < edge_count[i]; j++) {
            int u, v;
            cin >> u >> v;
            u--; v--;

            graph[i][u].push_back(v);
            graph[i][v].push_back(u);
        }
    }

    vector components(2, vector<int>(n));

    for (int i = 0; i < 2; i++) {
        vector<bool> done(n);

        for (int j = 0; j < n; j++)
            if (!done[j])
                dfs(graph[i], done, components[i], j, j);
    }

    map<pair<int, int>, int> cp;

    for (int i = 0; i < n; i++)
        cp[{ components[0][i], components[1][i] }]++;

    for (int i = 0; i < n; i++)
        cout << cp[{ components[0][i], components[1][i] }] - 1 << " ";
    cout << "\n";
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/03ms1848 KiB
2Elfogadva0/0136ms21284 KiB
3Elfogadva1/13ms2128 KiB
4Elfogadva1/13ms2328 KiB
5Elfogadva1/13ms2532 KiB
6Elfogadva1/13ms2620 KiB
7Elfogadva1/13ms2752 KiB
8Elfogadva1/13ms2964 KiB
9Elfogadva1/13ms3052 KiB
10Elfogadva1/14ms3608 KiB
11Elfogadva2/24ms3592 KiB
12Elfogadva2/24ms3668 KiB
13Elfogadva2/217ms4576 KiB
14Elfogadva2/213ms4348 KiB
15Elfogadva2/252ms12828 KiB
16Elfogadva2/274ms16172 KiB
17Elfogadva3/392ms19204 KiB
18Elfogadva3/393ms19600 KiB
19Elfogadva2/282ms13192 KiB
20Elfogadva2/2109ms17144 KiB
21Elfogadva2/2127ms18032 KiB
22Elfogadva2/2115ms19556 KiB
23Elfogadva3/3170ms21276 KiB
24Elfogadva3/3181ms22820 KiB