#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
#define f first
#define s second
#define LOGN 21
const ll MOD = 1e9 + 7;
const ll MAXN = 2e5 + 100;
#define int long long
int val[MAXN], par[MAXN], sz[MAXN], sum[MAXN];
vector<vector<int>> graph;
map<int,vector<int>> mp;
set<int> st[MAXN];
int find(int node) {
if (node == par[node])
return node;
return par[node] = find(par[node]);
}
void unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b)
return ;
if (sz[b] > sz[a])
swap(a, b);
sz[a] += sz[b];
par[b] = a;
sum[a] += sum[b];
if (st[b].size() > st[a].size())
swap(st[b], st[a]);
for (auto u : st[b])
st[a].insert(u);
}
signed main() {
fast;
for (int i = 0; i < MAXN; i++) {
par[i] = i, sz[i] = 1, sum[i] = 0;
st[i].insert(i);
}
int N, M;
cin >> N >> M;
graph = vector<vector<int>>(N+1, vector<int>());
for (int i = 1; i <= N; i++) {
cin >> val[i];
sum[i] = val[i];
mp[val[i]].push_back(i);
}
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
for (auto step : mp) {
int vl = step.f;
vector<int> nodes = step.s;
for (auto node : nodes) {
for (auto u : graph[node]) {
if (val[u] < val[node]) {
if (sum[find(u)] < val[node])
st[find(u)] = set<int>();
}
}
}
for (auto node : nodes) {
for (auto u : graph[node]) {
if (val[u] <= val[node])
unite(node, u);
}
}
}
for (int i = 1; i <= N; i++) {
if (st[find(i)].count(i))
cout << "1";
else
cout << "0";
}
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:64:13: warning: unused variable 'vl' [-Wunused-variable]
64 | int vl = step.f;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
24156 KB |
Output is correct |
2 |
Correct |
13 ms |
24240 KB |
Output is correct |
3 |
Correct |
16 ms |
24388 KB |
Output is correct |
4 |
Correct |
14 ms |
24684 KB |
Output is correct |
5 |
Correct |
14 ms |
24668 KB |
Output is correct |
6 |
Correct |
15 ms |
24576 KB |
Output is correct |
7 |
Correct |
12 ms |
24668 KB |
Output is correct |
8 |
Correct |
14 ms |
24664 KB |
Output is correct |
9 |
Correct |
13 ms |
24412 KB |
Output is correct |
10 |
Correct |
15 ms |
24660 KB |
Output is correct |
11 |
Correct |
14 ms |
24668 KB |
Output is correct |
12 |
Correct |
14 ms |
24668 KB |
Output is correct |
13 |
Correct |
13 ms |
24668 KB |
Output is correct |
14 |
Correct |
18 ms |
24652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
24152 KB |
Output is correct |
2 |
Correct |
13 ms |
24156 KB |
Output is correct |
3 |
Correct |
235 ms |
69776 KB |
Output is correct |
4 |
Correct |
152 ms |
53312 KB |
Output is correct |
5 |
Correct |
260 ms |
78252 KB |
Output is correct |
6 |
Correct |
253 ms |
76676 KB |
Output is correct |
7 |
Correct |
275 ms |
80764 KB |
Output is correct |
8 |
Correct |
230 ms |
55876 KB |
Output is correct |
9 |
Correct |
208 ms |
85644 KB |
Output is correct |
10 |
Correct |
145 ms |
58820 KB |
Output is correct |
11 |
Correct |
184 ms |
55500 KB |
Output is correct |
12 |
Correct |
229 ms |
52460 KB |
Output is correct |
13 |
Correct |
119 ms |
53448 KB |
Output is correct |
14 |
Correct |
137 ms |
52288 KB |
Output is correct |
15 |
Correct |
188 ms |
72276 KB |
Output is correct |
16 |
Correct |
173 ms |
71252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
24156 KB |
Output is correct |
2 |
Correct |
384 ms |
87032 KB |
Output is correct |
3 |
Correct |
353 ms |
82308 KB |
Output is correct |
4 |
Correct |
195 ms |
54812 KB |
Output is correct |
5 |
Correct |
126 ms |
53444 KB |
Output is correct |
6 |
Correct |
418 ms |
86388 KB |
Output is correct |
7 |
Correct |
223 ms |
72344 KB |
Output is correct |
8 |
Correct |
224 ms |
72420 KB |
Output is correct |
9 |
Correct |
171 ms |
71252 KB |
Output is correct |
10 |
Correct |
171 ms |
53444 KB |
Output is correct |
11 |
Correct |
172 ms |
50572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
24152 KB |
Output is correct |
2 |
Correct |
239 ms |
54420 KB |
Output is correct |
3 |
Correct |
244 ms |
57436 KB |
Output is correct |
4 |
Correct |
300 ms |
65684 KB |
Output is correct |
5 |
Correct |
333 ms |
81348 KB |
Output is correct |
6 |
Correct |
296 ms |
68596 KB |
Output is correct |
7 |
Correct |
179 ms |
56516 KB |
Output is correct |
8 |
Correct |
107 ms |
48968 KB |
Output is correct |
9 |
Correct |
119 ms |
40304 KB |
Output is correct |
10 |
Correct |
313 ms |
86904 KB |
Output is correct |
11 |
Correct |
146 ms |
49692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
24156 KB |
Output is correct |
2 |
Correct |
13 ms |
24240 KB |
Output is correct |
3 |
Correct |
16 ms |
24388 KB |
Output is correct |
4 |
Correct |
14 ms |
24684 KB |
Output is correct |
5 |
Correct |
14 ms |
24668 KB |
Output is correct |
6 |
Correct |
15 ms |
24576 KB |
Output is correct |
7 |
Correct |
12 ms |
24668 KB |
Output is correct |
8 |
Correct |
14 ms |
24664 KB |
Output is correct |
9 |
Correct |
13 ms |
24412 KB |
Output is correct |
10 |
Correct |
15 ms |
24660 KB |
Output is correct |
11 |
Correct |
14 ms |
24668 KB |
Output is correct |
12 |
Correct |
14 ms |
24668 KB |
Output is correct |
13 |
Correct |
13 ms |
24668 KB |
Output is correct |
14 |
Correct |
18 ms |
24652 KB |
Output is correct |
15 |
Correct |
12 ms |
24152 KB |
Output is correct |
16 |
Correct |
13 ms |
24156 KB |
Output is correct |
17 |
Correct |
235 ms |
69776 KB |
Output is correct |
18 |
Correct |
152 ms |
53312 KB |
Output is correct |
19 |
Correct |
260 ms |
78252 KB |
Output is correct |
20 |
Correct |
253 ms |
76676 KB |
Output is correct |
21 |
Correct |
275 ms |
80764 KB |
Output is correct |
22 |
Correct |
230 ms |
55876 KB |
Output is correct |
23 |
Correct |
208 ms |
85644 KB |
Output is correct |
24 |
Correct |
145 ms |
58820 KB |
Output is correct |
25 |
Correct |
184 ms |
55500 KB |
Output is correct |
26 |
Correct |
229 ms |
52460 KB |
Output is correct |
27 |
Correct |
119 ms |
53448 KB |
Output is correct |
28 |
Correct |
137 ms |
52288 KB |
Output is correct |
29 |
Correct |
188 ms |
72276 KB |
Output is correct |
30 |
Correct |
173 ms |
71252 KB |
Output is correct |
31 |
Correct |
11 ms |
24156 KB |
Output is correct |
32 |
Correct |
384 ms |
87032 KB |
Output is correct |
33 |
Correct |
353 ms |
82308 KB |
Output is correct |
34 |
Correct |
195 ms |
54812 KB |
Output is correct |
35 |
Correct |
126 ms |
53444 KB |
Output is correct |
36 |
Correct |
418 ms |
86388 KB |
Output is correct |
37 |
Correct |
223 ms |
72344 KB |
Output is correct |
38 |
Correct |
224 ms |
72420 KB |
Output is correct |
39 |
Correct |
171 ms |
71252 KB |
Output is correct |
40 |
Correct |
171 ms |
53444 KB |
Output is correct |
41 |
Correct |
172 ms |
50572 KB |
Output is correct |
42 |
Correct |
11 ms |
24152 KB |
Output is correct |
43 |
Correct |
239 ms |
54420 KB |
Output is correct |
44 |
Correct |
244 ms |
57436 KB |
Output is correct |
45 |
Correct |
300 ms |
65684 KB |
Output is correct |
46 |
Correct |
333 ms |
81348 KB |
Output is correct |
47 |
Correct |
296 ms |
68596 KB |
Output is correct |
48 |
Correct |
179 ms |
56516 KB |
Output is correct |
49 |
Correct |
107 ms |
48968 KB |
Output is correct |
50 |
Correct |
119 ms |
40304 KB |
Output is correct |
51 |
Correct |
313 ms |
86904 KB |
Output is correct |
52 |
Correct |
146 ms |
49692 KB |
Output is correct |
53 |
Correct |
12 ms |
24152 KB |
Output is correct |
54 |
Correct |
12 ms |
24156 KB |
Output is correct |
55 |
Correct |
12 ms |
24152 KB |
Output is correct |
56 |
Correct |
14 ms |
24668 KB |
Output is correct |
57 |
Correct |
14 ms |
24664 KB |
Output is correct |
58 |
Correct |
14 ms |
24704 KB |
Output is correct |
59 |
Correct |
13 ms |
24668 KB |
Output is correct |
60 |
Correct |
12 ms |
24696 KB |
Output is correct |
61 |
Correct |
13 ms |
24412 KB |
Output is correct |
62 |
Correct |
14 ms |
24724 KB |
Output is correct |
63 |
Correct |
14 ms |
24664 KB |
Output is correct |
64 |
Correct |
13 ms |
24668 KB |
Output is correct |
65 |
Correct |
12 ms |
24532 KB |
Output is correct |
66 |
Correct |
13 ms |
24668 KB |
Output is correct |
67 |
Correct |
195 ms |
69804 KB |
Output is correct |
68 |
Correct |
124 ms |
53316 KB |
Output is correct |
69 |
Correct |
302 ms |
78264 KB |
Output is correct |
70 |
Correct |
242 ms |
76628 KB |
Output is correct |
71 |
Correct |
337 ms |
80676 KB |
Output is correct |
72 |
Correct |
223 ms |
56008 KB |
Output is correct |
73 |
Correct |
207 ms |
85468 KB |
Output is correct |
74 |
Correct |
175 ms |
59072 KB |
Output is correct |
75 |
Correct |
229 ms |
55496 KB |
Output is correct |
76 |
Correct |
177 ms |
52284 KB |
Output is correct |
77 |
Correct |
129 ms |
53240 KB |
Output is correct |
78 |
Correct |
141 ms |
52288 KB |
Output is correct |
79 |
Correct |
204 ms |
72212 KB |
Output is correct |
80 |
Correct |
185 ms |
71248 KB |
Output is correct |
81 |
Correct |
382 ms |
86980 KB |
Output is correct |
82 |
Correct |
327 ms |
82104 KB |
Output is correct |
83 |
Correct |
161 ms |
54868 KB |
Output is correct |
84 |
Correct |
125 ms |
53448 KB |
Output is correct |
85 |
Correct |
362 ms |
86516 KB |
Output is correct |
86 |
Correct |
199 ms |
72452 KB |
Output is correct |
87 |
Correct |
247 ms |
72276 KB |
Output is correct |
88 |
Correct |
161 ms |
53440 KB |
Output is correct |
89 |
Correct |
162 ms |
50624 KB |
Output is correct |
90 |
Correct |
289 ms |
54596 KB |
Output is correct |
91 |
Correct |
255 ms |
57572 KB |
Output is correct |
92 |
Correct |
291 ms |
65564 KB |
Output is correct |
93 |
Correct |
343 ms |
81352 KB |
Output is correct |
94 |
Correct |
291 ms |
68516 KB |
Output is correct |
95 |
Correct |
177 ms |
56372 KB |
Output is correct |
96 |
Correct |
112 ms |
48968 KB |
Output is correct |
97 |
Correct |
132 ms |
40140 KB |
Output is correct |
98 |
Correct |
311 ms |
87072 KB |
Output is correct |
99 |
Correct |
161 ms |
49828 KB |
Output is correct |
100 |
Correct |
44 ms |
31060 KB |
Output is correct |
101 |
Correct |
391 ms |
73408 KB |
Output is correct |
102 |
Correct |
225 ms |
57792 KB |
Output is correct |
103 |
Correct |
295 ms |
58704 KB |
Output is correct |
104 |
Correct |
375 ms |
70480 KB |
Output is correct |