#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<pii> village(n);
vector<vector<int>> G(n + 1);
vector<int> parent(n + 1), parent1(n + 1);
vector<ll> vsize(n + 1);
for(int i = 1; i <= n; i++) {
int a;
cin >> a;
village[i - 1] = {a, i};
parent1[i] = parent[i] = i;
}
sort(village.begin(), village.end());
for(int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
}
vector<bool> visited(n + 1);
for(auto [vs, v] : village) {
vsize[v] = vs;
visited[v] = true;
for(int u : G[v]) {
if(!visited[u]) continue;
while(u != parent[u])
u = parent[u] = parent[parent[u]];
if(u == v)
continue;
vsize[v] += vsize[u];
parent[u] = v;
if(vsize[u] >= vs)
parent1[u] = v;
}
}
int v = village.back().second;
for(int i = 1; i <= n; i++) {
int u = i;
while(u != parent1[u])
u = parent1[u] = parent1[parent1[u]];
if(u == v)
cout << '1';
else
cout << '0';
}
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:30:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
30 | for(auto [vs, v] : village) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
73 ms |
20564 KB |
Output is correct |
4 |
Correct |
68 ms |
19284 KB |
Output is correct |
5 |
Correct |
71 ms |
19872 KB |
Output is correct |
6 |
Correct |
72 ms |
20696 KB |
Output is correct |
7 |
Correct |
71 ms |
20564 KB |
Output is correct |
8 |
Correct |
89 ms |
20560 KB |
Output is correct |
9 |
Correct |
71 ms |
20560 KB |
Output is correct |
10 |
Correct |
59 ms |
20676 KB |
Output is correct |
11 |
Correct |
75 ms |
20328 KB |
Output is correct |
12 |
Correct |
79 ms |
19284 KB |
Output is correct |
13 |
Correct |
70 ms |
19076 KB |
Output is correct |
14 |
Correct |
66 ms |
19220 KB |
Output is correct |
15 |
Correct |
71 ms |
20560 KB |
Output is correct |
16 |
Correct |
52 ms |
19792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
88 ms |
20412 KB |
Output is correct |
3 |
Correct |
87 ms |
20776 KB |
Output is correct |
4 |
Correct |
87 ms |
20700 KB |
Output is correct |
5 |
Correct |
65 ms |
19028 KB |
Output is correct |
6 |
Correct |
81 ms |
20560 KB |
Output is correct |
7 |
Correct |
80 ms |
20560 KB |
Output is correct |
8 |
Correct |
84 ms |
20708 KB |
Output is correct |
9 |
Correct |
49 ms |
19796 KB |
Output is correct |
10 |
Correct |
71 ms |
20048 KB |
Output is correct |
11 |
Correct |
78 ms |
19284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
94 ms |
20544 KB |
Output is correct |
3 |
Correct |
90 ms |
20688 KB |
Output is correct |
4 |
Correct |
95 ms |
20968 KB |
Output is correct |
5 |
Correct |
98 ms |
20556 KB |
Output is correct |
6 |
Correct |
79 ms |
19796 KB |
Output is correct |
7 |
Correct |
65 ms |
21448 KB |
Output is correct |
8 |
Correct |
57 ms |
19540 KB |
Output is correct |
9 |
Correct |
62 ms |
11860 KB |
Output is correct |
10 |
Correct |
76 ms |
19284 KB |
Output is correct |
11 |
Correct |
85 ms |
19280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
73 ms |
20564 KB |
Output is correct |
18 |
Correct |
68 ms |
19284 KB |
Output is correct |
19 |
Correct |
71 ms |
19872 KB |
Output is correct |
20 |
Correct |
72 ms |
20696 KB |
Output is correct |
21 |
Correct |
71 ms |
20564 KB |
Output is correct |
22 |
Correct |
89 ms |
20560 KB |
Output is correct |
23 |
Correct |
71 ms |
20560 KB |
Output is correct |
24 |
Correct |
59 ms |
20676 KB |
Output is correct |
25 |
Correct |
75 ms |
20328 KB |
Output is correct |
26 |
Correct |
79 ms |
19284 KB |
Output is correct |
27 |
Correct |
70 ms |
19076 KB |
Output is correct |
28 |
Correct |
66 ms |
19220 KB |
Output is correct |
29 |
Correct |
71 ms |
20560 KB |
Output is correct |
30 |
Correct |
52 ms |
19792 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
88 ms |
20412 KB |
Output is correct |
33 |
Correct |
87 ms |
20776 KB |
Output is correct |
34 |
Correct |
87 ms |
20700 KB |
Output is correct |
35 |
Correct |
65 ms |
19028 KB |
Output is correct |
36 |
Correct |
81 ms |
20560 KB |
Output is correct |
37 |
Correct |
80 ms |
20560 KB |
Output is correct |
38 |
Correct |
84 ms |
20708 KB |
Output is correct |
39 |
Correct |
49 ms |
19796 KB |
Output is correct |
40 |
Correct |
71 ms |
20048 KB |
Output is correct |
41 |
Correct |
78 ms |
19284 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
94 ms |
20544 KB |
Output is correct |
44 |
Correct |
90 ms |
20688 KB |
Output is correct |
45 |
Correct |
95 ms |
20968 KB |
Output is correct |
46 |
Correct |
98 ms |
20556 KB |
Output is correct |
47 |
Correct |
79 ms |
19796 KB |
Output is correct |
48 |
Correct |
65 ms |
21448 KB |
Output is correct |
49 |
Correct |
57 ms |
19540 KB |
Output is correct |
50 |
Correct |
62 ms |
11860 KB |
Output is correct |
51 |
Correct |
76 ms |
19284 KB |
Output is correct |
52 |
Correct |
85 ms |
19280 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
604 KB |
Output is correct |
57 |
Correct |
1 ms |
468 KB |
Output is correct |
58 |
Correct |
1 ms |
604 KB |
Output is correct |
59 |
Correct |
1 ms |
604 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
1 ms |
608 KB |
Output is correct |
62 |
Correct |
1 ms |
600 KB |
Output is correct |
63 |
Correct |
1 ms |
604 KB |
Output is correct |
64 |
Correct |
1 ms |
604 KB |
Output is correct |
65 |
Correct |
1 ms |
604 KB |
Output is correct |
66 |
Correct |
1 ms |
604 KB |
Output is correct |
67 |
Correct |
74 ms |
20776 KB |
Output is correct |
68 |
Correct |
72 ms |
19280 KB |
Output is correct |
69 |
Correct |
72 ms |
20048 KB |
Output is correct |
70 |
Correct |
80 ms |
20572 KB |
Output is correct |
71 |
Correct |
81 ms |
20560 KB |
Output is correct |
72 |
Correct |
87 ms |
20568 KB |
Output is correct |
73 |
Correct |
76 ms |
20560 KB |
Output is correct |
74 |
Correct |
67 ms |
20680 KB |
Output is correct |
75 |
Correct |
72 ms |
20524 KB |
Output is correct |
76 |
Correct |
87 ms |
19280 KB |
Output is correct |
77 |
Correct |
70 ms |
19024 KB |
Output is correct |
78 |
Correct |
71 ms |
19280 KB |
Output is correct |
79 |
Correct |
76 ms |
20592 KB |
Output is correct |
80 |
Correct |
55 ms |
19796 KB |
Output is correct |
81 |
Correct |
97 ms |
20564 KB |
Output is correct |
82 |
Correct |
90 ms |
20560 KB |
Output is correct |
83 |
Correct |
91 ms |
20560 KB |
Output is correct |
84 |
Correct |
67 ms |
19020 KB |
Output is correct |
85 |
Correct |
92 ms |
20600 KB |
Output is correct |
86 |
Correct |
81 ms |
20712 KB |
Output is correct |
87 |
Correct |
79 ms |
20560 KB |
Output is correct |
88 |
Correct |
71 ms |
20052 KB |
Output is correct |
89 |
Correct |
74 ms |
19280 KB |
Output is correct |
90 |
Correct |
97 ms |
20560 KB |
Output is correct |
91 |
Correct |
89 ms |
20544 KB |
Output is correct |
92 |
Correct |
103 ms |
20640 KB |
Output is correct |
93 |
Correct |
92 ms |
20604 KB |
Output is correct |
94 |
Correct |
77 ms |
19796 KB |
Output is correct |
95 |
Correct |
66 ms |
21452 KB |
Output is correct |
96 |
Correct |
59 ms |
19536 KB |
Output is correct |
97 |
Correct |
67 ms |
11856 KB |
Output is correct |
98 |
Correct |
76 ms |
19284 KB |
Output is correct |
99 |
Correct |
78 ms |
19284 KB |
Output is correct |
100 |
Correct |
29 ms |
4688 KB |
Output is correct |
101 |
Correct |
102 ms |
20816 KB |
Output is correct |
102 |
Correct |
113 ms |
16724 KB |
Output is correct |
103 |
Correct |
94 ms |
17700 KB |
Output is correct |
104 |
Correct |
95 ms |
20380 KB |
Output is correct |