#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define OPT ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define inf 0x3F3F3F3F
#define bpc __builtin_popcount
#define print(v) for(int i = 0; i < v.size(); i++) \
cout << v[i] << " "; \
cout<<endl;
ll n;
vector<ll> v(200001);
vector<ll> d[200001];
vector<ll> sum(200001);
vector<bool> ans(200001, true);
vector<ll> e(200001, -1);
vector<vector<ll>> adj(200001);
void init(int n)
{
for (int i = 1; i <= n; i++)
{
d[i].pb(i);
sum[i] = v[i];
}
}
int get(int x)
{
if (e[x] < 0) return x;
return e[x] = get(e[x]);
}
int s(int x)
{
return -e[get(x)];
}
void unite(int x, int y)
{
x = get(x);
y = get(y);
if (x == y) return;
if (e[x] > e[y]) swap(x, y);
e[x] += e[y];
e[y] = x;
sum[x] += sum[y];
for (int i = 0; i < d[y].size(); i++)
{
d[x].pb(d[y][i]);
}
}
ll get_sum(int x)
{
x = get(x);
return sum[x];
}
int main()
{
int m;
cin >> n >> m;
vector<pii> arr(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> v[i];
arr[i].fi = v[i];
arr[i].se = i;
}
while (m--)
{
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
sort(arr.begin() + 1, arr.end());
init(n);
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < adj[arr[i].se].size(); j++)
{
int x = arr[i].se;
int y = adj[x][j];
if (arr[i].fi < v[y]) continue;
int z = get(y);
if (sum[z] < arr[i].fi)
{
for (int k = 0; k < d[z].size(); k++)
{
ans[d[z][k]] = false;
}
}
unite(x, y);
}
}
for (int i = 1; i <= n; i++) cout << ans[i];
}
Compilation message
island.cpp: In function 'void unite(int, int)':
island.cpp:67:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int i = 0; i < d[y].size(); i++)
| ~~^~~~~~~~~~~~~
island.cpp: In function 'int main()':
island.cpp:105:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for (int j = 0; j < adj[arr[i].se].size(); j++)
| ~~^~~~~~~~~~~~~~~~~~~~~~~
island.cpp:115:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | for (int k = 0; k < d[z].size(); k++)
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
7 ms |
14420 KB |
Output is correct |
4 |
Correct |
9 ms |
14548 KB |
Output is correct |
5 |
Correct |
9 ms |
14588 KB |
Output is correct |
6 |
Correct |
9 ms |
14548 KB |
Output is correct |
7 |
Correct |
9 ms |
14576 KB |
Output is correct |
8 |
Correct |
10 ms |
14496 KB |
Output is correct |
9 |
Correct |
9 ms |
14536 KB |
Output is correct |
10 |
Correct |
10 ms |
14644 KB |
Output is correct |
11 |
Correct |
12 ms |
14704 KB |
Output is correct |
12 |
Correct |
9 ms |
14760 KB |
Output is correct |
13 |
Correct |
8 ms |
14504 KB |
Output is correct |
14 |
Correct |
9 ms |
14576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14432 KB |
Output is correct |
3 |
Correct |
304 ms |
36872 KB |
Output is correct |
4 |
Correct |
251 ms |
34584 KB |
Output is correct |
5 |
Correct |
321 ms |
43488 KB |
Output is correct |
6 |
Correct |
345 ms |
44448 KB |
Output is correct |
7 |
Correct |
341 ms |
44884 KB |
Output is correct |
8 |
Correct |
314 ms |
36032 KB |
Output is correct |
9 |
Correct |
294 ms |
53816 KB |
Output is correct |
10 |
Correct |
244 ms |
36668 KB |
Output is correct |
11 |
Correct |
246 ms |
36556 KB |
Output is correct |
12 |
Correct |
281 ms |
36580 KB |
Output is correct |
13 |
Correct |
258 ms |
33644 KB |
Output is correct |
14 |
Correct |
250 ms |
33724 KB |
Output is correct |
15 |
Correct |
290 ms |
35172 KB |
Output is correct |
16 |
Correct |
204 ms |
34280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
424 ms |
47564 KB |
Output is correct |
3 |
Correct |
372 ms |
47680 KB |
Output is correct |
4 |
Correct |
291 ms |
35084 KB |
Output is correct |
5 |
Correct |
275 ms |
34136 KB |
Output is correct |
6 |
Correct |
372 ms |
47624 KB |
Output is correct |
7 |
Correct |
319 ms |
35176 KB |
Output is correct |
8 |
Correct |
290 ms |
35084 KB |
Output is correct |
9 |
Correct |
206 ms |
34252 KB |
Output is correct |
10 |
Correct |
264 ms |
34392 KB |
Output is correct |
11 |
Correct |
275 ms |
36592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
388 ms |
40252 KB |
Output is correct |
3 |
Correct |
375 ms |
41656 KB |
Output is correct |
4 |
Correct |
385 ms |
43304 KB |
Output is correct |
5 |
Correct |
370 ms |
41920 KB |
Output is correct |
6 |
Correct |
342 ms |
38364 KB |
Output is correct |
7 |
Correct |
277 ms |
37660 KB |
Output is correct |
8 |
Correct |
195 ms |
35540 KB |
Output is correct |
9 |
Correct |
213 ms |
28988 KB |
Output is correct |
10 |
Correct |
317 ms |
41924 KB |
Output is correct |
11 |
Correct |
281 ms |
36108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
7 ms |
14420 KB |
Output is correct |
4 |
Correct |
9 ms |
14548 KB |
Output is correct |
5 |
Correct |
9 ms |
14588 KB |
Output is correct |
6 |
Correct |
9 ms |
14548 KB |
Output is correct |
7 |
Correct |
9 ms |
14576 KB |
Output is correct |
8 |
Correct |
10 ms |
14496 KB |
Output is correct |
9 |
Correct |
9 ms |
14536 KB |
Output is correct |
10 |
Correct |
10 ms |
14644 KB |
Output is correct |
11 |
Correct |
12 ms |
14704 KB |
Output is correct |
12 |
Correct |
9 ms |
14760 KB |
Output is correct |
13 |
Correct |
8 ms |
14504 KB |
Output is correct |
14 |
Correct |
9 ms |
14576 KB |
Output is correct |
15 |
Correct |
7 ms |
14420 KB |
Output is correct |
16 |
Correct |
7 ms |
14432 KB |
Output is correct |
17 |
Correct |
304 ms |
36872 KB |
Output is correct |
18 |
Correct |
251 ms |
34584 KB |
Output is correct |
19 |
Correct |
321 ms |
43488 KB |
Output is correct |
20 |
Correct |
345 ms |
44448 KB |
Output is correct |
21 |
Correct |
341 ms |
44884 KB |
Output is correct |
22 |
Correct |
314 ms |
36032 KB |
Output is correct |
23 |
Correct |
294 ms |
53816 KB |
Output is correct |
24 |
Correct |
244 ms |
36668 KB |
Output is correct |
25 |
Correct |
246 ms |
36556 KB |
Output is correct |
26 |
Correct |
281 ms |
36580 KB |
Output is correct |
27 |
Correct |
258 ms |
33644 KB |
Output is correct |
28 |
Correct |
250 ms |
33724 KB |
Output is correct |
29 |
Correct |
290 ms |
35172 KB |
Output is correct |
30 |
Correct |
204 ms |
34280 KB |
Output is correct |
31 |
Correct |
7 ms |
14420 KB |
Output is correct |
32 |
Correct |
424 ms |
47564 KB |
Output is correct |
33 |
Correct |
372 ms |
47680 KB |
Output is correct |
34 |
Correct |
291 ms |
35084 KB |
Output is correct |
35 |
Correct |
275 ms |
34136 KB |
Output is correct |
36 |
Correct |
372 ms |
47624 KB |
Output is correct |
37 |
Correct |
319 ms |
35176 KB |
Output is correct |
38 |
Correct |
290 ms |
35084 KB |
Output is correct |
39 |
Correct |
206 ms |
34252 KB |
Output is correct |
40 |
Correct |
264 ms |
34392 KB |
Output is correct |
41 |
Correct |
275 ms |
36592 KB |
Output is correct |
42 |
Correct |
8 ms |
14420 KB |
Output is correct |
43 |
Correct |
388 ms |
40252 KB |
Output is correct |
44 |
Correct |
375 ms |
41656 KB |
Output is correct |
45 |
Correct |
385 ms |
43304 KB |
Output is correct |
46 |
Correct |
370 ms |
41920 KB |
Output is correct |
47 |
Correct |
342 ms |
38364 KB |
Output is correct |
48 |
Correct |
277 ms |
37660 KB |
Output is correct |
49 |
Correct |
195 ms |
35540 KB |
Output is correct |
50 |
Correct |
213 ms |
28988 KB |
Output is correct |
51 |
Correct |
317 ms |
41924 KB |
Output is correct |
52 |
Correct |
281 ms |
36108 KB |
Output is correct |
53 |
Correct |
7 ms |
14420 KB |
Output is correct |
54 |
Correct |
6 ms |
14420 KB |
Output is correct |
55 |
Correct |
7 ms |
14312 KB |
Output is correct |
56 |
Correct |
8 ms |
14604 KB |
Output is correct |
57 |
Correct |
9 ms |
14624 KB |
Output is correct |
58 |
Correct |
8 ms |
14548 KB |
Output is correct |
59 |
Correct |
9 ms |
14548 KB |
Output is correct |
60 |
Correct |
9 ms |
14548 KB |
Output is correct |
61 |
Correct |
9 ms |
14572 KB |
Output is correct |
62 |
Correct |
11 ms |
14676 KB |
Output is correct |
63 |
Correct |
9 ms |
14696 KB |
Output is correct |
64 |
Correct |
10 ms |
14676 KB |
Output is correct |
65 |
Correct |
9 ms |
14572 KB |
Output is correct |
66 |
Correct |
8 ms |
14572 KB |
Output is correct |
67 |
Correct |
288 ms |
36936 KB |
Output is correct |
68 |
Correct |
264 ms |
34616 KB |
Output is correct |
69 |
Correct |
328 ms |
43504 KB |
Output is correct |
70 |
Correct |
359 ms |
44544 KB |
Output is correct |
71 |
Correct |
329 ms |
44816 KB |
Output is correct |
72 |
Correct |
320 ms |
35944 KB |
Output is correct |
73 |
Correct |
323 ms |
53756 KB |
Output is correct |
74 |
Correct |
273 ms |
36668 KB |
Output is correct |
75 |
Correct |
251 ms |
36540 KB |
Output is correct |
76 |
Correct |
286 ms |
36576 KB |
Output is correct |
77 |
Correct |
223 ms |
33620 KB |
Output is correct |
78 |
Correct |
255 ms |
33736 KB |
Output is correct |
79 |
Correct |
262 ms |
35060 KB |
Output is correct |
80 |
Correct |
239 ms |
34260 KB |
Output is correct |
81 |
Correct |
378 ms |
47540 KB |
Output is correct |
82 |
Correct |
363 ms |
47696 KB |
Output is correct |
83 |
Correct |
299 ms |
35080 KB |
Output is correct |
84 |
Correct |
243 ms |
34204 KB |
Output is correct |
85 |
Correct |
382 ms |
47812 KB |
Output is correct |
86 |
Correct |
304 ms |
35144 KB |
Output is correct |
87 |
Correct |
304 ms |
35180 KB |
Output is correct |
88 |
Correct |
291 ms |
34468 KB |
Output is correct |
89 |
Correct |
293 ms |
36576 KB |
Output is correct |
90 |
Correct |
453 ms |
40300 KB |
Output is correct |
91 |
Correct |
440 ms |
41616 KB |
Output is correct |
92 |
Correct |
480 ms |
43144 KB |
Output is correct |
93 |
Correct |
438 ms |
41852 KB |
Output is correct |
94 |
Correct |
387 ms |
38448 KB |
Output is correct |
95 |
Correct |
347 ms |
37496 KB |
Output is correct |
96 |
Correct |
208 ms |
35536 KB |
Output is correct |
97 |
Correct |
255 ms |
29144 KB |
Output is correct |
98 |
Correct |
363 ms |
42012 KB |
Output is correct |
99 |
Correct |
288 ms |
36104 KB |
Output is correct |
100 |
Correct |
108 ms |
20820 KB |
Output is correct |
101 |
Correct |
396 ms |
42824 KB |
Output is correct |
102 |
Correct |
291 ms |
34788 KB |
Output is correct |
103 |
Correct |
354 ms |
35392 KB |
Output is correct |
104 |
Correct |
369 ms |
39192 KB |
Output is correct |