Submission #1069307


Source Code Expand

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define ll long long
using namespace std;

const int maxn = 200010;
int n, m1, m2, u, v;
int f1[maxn], f2[maxn], vis[maxn], cnt[maxn], res[maxn];
vector <int> G[maxn];

int Find1 (int x) {
	if (f1[x] == x) return x;
	return f1[x] = Find1(f1[x]);
}

int Find2 (int x) {
	if (f2[x] == x) return x;
	return f2[x] = Find2(f2[x]);
}

int main () {
	scanf ("%d%d%d", &n, &m1, &m2);
	for (int i = 1; i <= n; i++) f1[i]= f2[i] = i;
	for (int i = 0; i < m1; i++) {
        scanf ("%d%d", &u, &v);
        f1[Find1(u)] = Find1(v);
	}
	for (int i = 0; i < m2; i++) {
        scanf ("%d%d", &u, &v);
        f2[Find2(u)] = Find2(v);
	}
    for (int i = 1; i <= n; i++) G[Find1(i)].push_back(i);
    for (int i = 1; i <= n; i++) if(G[i].size()) {
        for (int j = 0; j < G[i].size(); j++) {
            int t = Find2(G[i][j]);
            if (vis[t] != i) {
                vis[t] = i;
                cnt[t] = 0;
            }
            cnt[t]++;
        }
        for (int j = 0; j < G[i].size(); j++) {
            int t = Find2(G[i][j]);
            res[G[i][j]] = cnt[t];
        }
    }
    for (int i = 1; i <= n; i++) printf("%d%c", res[i], i==n?'\n':' ');
	return 0;
}

Submission Info

Submission Time
Task D - Connectivity
User vjudge1
Language Bash (GNU bash v4.3.11)
Score 0
Code Size 1247 Byte
Status RE
Exec Time 11 ms
Memory 592 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
RE × 3
RE × 18
Set Name Test Cases
Sample subtask0_0.txt, subtask0_1.txt, subtask0_2.txt
All subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask1_0.txt, subtask1_1.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_2.txt, subtask1_3.txt, subtask1_4.txt, subtask1_5.txt, subtask1_6.txt, subtask1_7.txt, subtask1_8.txt, subtask1_9.txt
Case Name Status Exec Time Memory
subtask0_0.txt RE 11 ms 592 KB
subtask0_1.txt RE 10 ms 584 KB
subtask0_2.txt RE 10 ms 584 KB
subtask1_0.txt RE 10 ms 584 KB
subtask1_1.txt RE 10 ms 584 KB
subtask1_10.txt RE 10 ms 592 KB
subtask1_11.txt RE 10 ms 584 KB
subtask1_12.txt RE 11 ms 584 KB
subtask1_13.txt RE 10 ms 584 KB
subtask1_14.txt RE 11 ms 592 KB
subtask1_2.txt RE 10 ms 584 KB
subtask1_3.txt RE 10 ms 584 KB
subtask1_4.txt RE 10 ms 584 KB
subtask1_5.txt RE 10 ms 592 KB
subtask1_6.txt RE 11 ms 584 KB
subtask1_7.txt RE 10 ms 584 KB
subtask1_8.txt RE 11 ms 584 KB
subtask1_9.txt RE 11 ms 592 KB