Submission #1069308
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 |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
1247 Byte |
Status |
AC |
Exec Time |
83 ms |
Memory |
14720 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:24:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d%d", &n, &m1, &m2);
^
./Main.cpp:27:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d", &u, &v);
^
./Main.cpp:31:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d", &u, &v);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
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 |
AC |
8 ms |
4992 KB |
subtask0_1.txt |
AC |
8 ms |
4992 KB |
subtask0_2.txt |
AC |
8 ms |
4992 KB |
subtask1_0.txt |
AC |
35 ms |
4992 KB |
subtask1_1.txt |
AC |
80 ms |
14720 KB |
subtask1_10.txt |
AC |
37 ms |
4992 KB |
subtask1_11.txt |
AC |
75 ms |
13696 KB |
subtask1_12.txt |
AC |
80 ms |
12408 KB |
subtask1_13.txt |
AC |
78 ms |
13436 KB |
subtask1_14.txt |
AC |
75 ms |
10496 KB |
subtask1_2.txt |
AC |
71 ms |
10616 KB |
subtask1_3.txt |
AC |
81 ms |
13304 KB |
subtask1_4.txt |
AC |
77 ms |
11008 KB |
subtask1_5.txt |
AC |
38 ms |
4992 KB |
subtask1_6.txt |
AC |
72 ms |
13184 KB |
subtask1_7.txt |
AC |
82 ms |
13432 KB |
subtask1_8.txt |
AC |
83 ms |
13304 KB |
subtask1_9.txt |
AC |
70 ms |
9344 KB |