13922022-08-30 15:01:08gtgSportos nyaraláscpp17Wrong answer 5/40170ms14776 KiB
#include <bits/stdc++.h>
using namespace std;
vector<int> p;
vector<int> r;
vector<vector<int> > g, group;
vector<bool> vis;
int findl(int n)
{
    if(p[n] == 0) return n;
    return p[n] = findl(p[n]);
}
void unio(int a, int b)
{
    a = findl(a);
    b = findl(b);
    if(a != b)
    {
        if(r[a] < r[b]) swap(a, b);
        p[b] = a;
        if(r[a] == r[b]) r[a]++;
    }
}
void dfs(int n)
{
    vis[n] = 1;
    group[group.size() - 1].push_back(n);
    for(auto x : g[n])
    {
        if(!vis[x])
        {
            dfs(x);
        }
    }
}
int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    p.resize(n + 1);
    r.resize(n + 1, 1);
    g.resize(n + 1);
    vis.resize(n + 1);
    int x, y;
    for (int i = 0; i < m; i++)
    {
        cin >> x >> y;
        unio(x, y);
    }
    for (int i = 0; i < k; i++)
    {
        cin >> x >> y;
        if(findl(x) == findl(y))
        {
            g[x].push_back(y);
            g[y].push_back(x);
        }
    }
    for(int i = 1; i <= n; i++)
    {
        if(!vis[i])
        {
            group.push_back({});
            dfs(i);
        }
    }
    vector<int> ans(n + 1);
    for(int i = 0; i < group.size(); i++)
    {
        for (auto j : group[i])
        {
            ans[j] = group[i].size() - 1;
        }
    }
    for(int i = 1; i <= n; i++) cout << ans[i] << " ";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base5/40
1Accepted0/03ms1812 KiB
2Wrong answer0/094ms10976 KiB
3Accepted1/12ms2260 KiB
4Accepted1/12ms2468 KiB
5Accepted1/12ms2668 KiB
6Accepted1/12ms2732 KiB
7Wrong answer0/12ms2732 KiB
8Wrong answer0/12ms2868 KiB
9Wrong answer0/12ms3008 KiB
10Accepted1/14ms3192 KiB
11Wrong answer0/24ms3300 KiB
12Wrong answer0/24ms3276 KiB
13Wrong answer0/216ms3788 KiB
14Wrong answer0/212ms3908 KiB
15Wrong answer0/235ms8700 KiB
16Wrong answer0/250ms10528 KiB
17Wrong answer0/357ms12492 KiB
18Wrong answer0/364ms13260 KiB
19Wrong answer0/271ms9548 KiB
20Wrong answer0/293ms11064 KiB
21Wrong answer0/2100ms12096 KiB
22Wrong answer0/287ms12500 KiB
23Wrong answer0/3134ms14280 KiB
24Wrong answer0/3170ms14776 KiB