13912022-08-30 14:41:59gtgSportos nyaraláscpp17Runtime error 4/4082ms127304 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(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
base4/40
1Accepted0/03ms1808 KiB
2Runtime error0/071ms126136 KiB
3Accepted1/12ms2320 KiB
4Accepted1/12ms2408 KiB
5Accepted1/12ms2488 KiB
6Accepted1/12ms2488 KiB
7Runtime error0/154ms126436 KiB
8Wrong answer0/12ms2492 KiB
9Runtime error0/165ms126672 KiB
10Runtime error0/156ms126752 KiB
11Runtime error0/265ms127112 KiB
12Runtime error0/257ms126856 KiB
13Runtime error0/257ms127184 KiB
14Runtime error0/257ms127136 KiB
15Runtime error0/264ms127088 KiB
16Runtime error0/268ms127304 KiB
17Wrong answer0/357ms12224 KiB
18Runtime error0/372ms127248 KiB
19Runtime error0/264ms127284 KiB
20Runtime error0/268ms127280 KiB
21Runtime error0/279ms127020 KiB
22Runtime error0/275ms126752 KiB
23Runtime error0/370ms126752 KiB
24Runtime error0/382ms126492 KiB