#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 |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14368 KB |
Output is correct |
3 |
Correct |
9 ms |
14420 KB |
Output is correct |
4 |
Correct |
12 ms |
14548 KB |
Output is correct |
5 |
Correct |
11 ms |
14548 KB |
Output is correct |
6 |
Correct |
10 ms |
14548 KB |
Output is correct |
7 |
Correct |
13 ms |
14548 KB |
Output is correct |
8 |
Correct |
9 ms |
14548 KB |
Output is correct |
9 |
Correct |
9 ms |
14576 KB |
Output is correct |
10 |
Correct |
10 ms |
14676 KB |
Output is correct |
11 |
Correct |
9 ms |
14612 KB |
Output is correct |
12 |
Correct |
9 ms |
14676 KB |
Output is correct |
13 |
Correct |
9 ms |
14548 KB |
Output is correct |
14 |
Correct |
9 ms |
14548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
292 ms |
32508 KB |
Output is correct |
4 |
Correct |
299 ms |
31464 KB |
Output is correct |
5 |
Correct |
331 ms |
39256 KB |
Output is correct |
6 |
Correct |
343 ms |
40148 KB |
Output is correct |
7 |
Correct |
349 ms |
40532 KB |
Output is correct |
8 |
Correct |
317 ms |
31632 KB |
Output is correct |
9 |
Correct |
344 ms |
49344 KB |
Output is correct |
10 |
Correct |
280 ms |
33236 KB |
Output is correct |
11 |
Correct |
257 ms |
33044 KB |
Output is correct |
12 |
Correct |
284 ms |
33508 KB |
Output is correct |
13 |
Correct |
263 ms |
30692 KB |
Output is correct |
14 |
Correct |
306 ms |
30692 KB |
Output is correct |
15 |
Correct |
299 ms |
30784 KB |
Output is correct |
16 |
Correct |
231 ms |
30416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
399 ms |
43448 KB |
Output is correct |
3 |
Correct |
416 ms |
43100 KB |
Output is correct |
4 |
Correct |
318 ms |
30664 KB |
Output is correct |
5 |
Correct |
244 ms |
31216 KB |
Output is correct |
6 |
Correct |
417 ms |
43172 KB |
Output is correct |
7 |
Correct |
291 ms |
30664 KB |
Output is correct |
8 |
Correct |
294 ms |
30764 KB |
Output is correct |
9 |
Correct |
217 ms |
30508 KB |
Output is correct |
10 |
Correct |
262 ms |
30572 KB |
Output is correct |
11 |
Correct |
337 ms |
33600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14420 KB |
Output is correct |
2 |
Correct |
423 ms |
35804 KB |
Output is correct |
3 |
Correct |
425 ms |
37184 KB |
Output is correct |
4 |
Correct |
404 ms |
38804 KB |
Output is correct |
5 |
Correct |
364 ms |
37460 KB |
Output is correct |
6 |
Correct |
377 ms |
34060 KB |
Output is correct |
7 |
Correct |
289 ms |
33128 KB |
Output is correct |
8 |
Correct |
210 ms |
32352 KB |
Output is correct |
9 |
Correct |
227 ms |
26464 KB |
Output is correct |
10 |
Correct |
335 ms |
39124 KB |
Output is correct |
11 |
Correct |
294 ms |
33072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14368 KB |
Output is correct |
3 |
Correct |
9 ms |
14420 KB |
Output is correct |
4 |
Correct |
12 ms |
14548 KB |
Output is correct |
5 |
Correct |
11 ms |
14548 KB |
Output is correct |
6 |
Correct |
10 ms |
14548 KB |
Output is correct |
7 |
Correct |
13 ms |
14548 KB |
Output is correct |
8 |
Correct |
9 ms |
14548 KB |
Output is correct |
9 |
Correct |
9 ms |
14576 KB |
Output is correct |
10 |
Correct |
10 ms |
14676 KB |
Output is correct |
11 |
Correct |
9 ms |
14612 KB |
Output is correct |
12 |
Correct |
9 ms |
14676 KB |
Output is correct |
13 |
Correct |
9 ms |
14548 KB |
Output is correct |
14 |
Correct |
9 ms |
14548 KB |
Output is correct |
15 |
Correct |
8 ms |
14420 KB |
Output is correct |
16 |
Correct |
7 ms |
14420 KB |
Output is correct |
17 |
Correct |
292 ms |
32508 KB |
Output is correct |
18 |
Correct |
299 ms |
31464 KB |
Output is correct |
19 |
Correct |
331 ms |
39256 KB |
Output is correct |
20 |
Correct |
343 ms |
40148 KB |
Output is correct |
21 |
Correct |
349 ms |
40532 KB |
Output is correct |
22 |
Correct |
317 ms |
31632 KB |
Output is correct |
23 |
Correct |
344 ms |
49344 KB |
Output is correct |
24 |
Correct |
280 ms |
33236 KB |
Output is correct |
25 |
Correct |
257 ms |
33044 KB |
Output is correct |
26 |
Correct |
284 ms |
33508 KB |
Output is correct |
27 |
Correct |
263 ms |
30692 KB |
Output is correct |
28 |
Correct |
306 ms |
30692 KB |
Output is correct |
29 |
Correct |
299 ms |
30784 KB |
Output is correct |
30 |
Correct |
231 ms |
30416 KB |
Output is correct |
31 |
Correct |
8 ms |
14420 KB |
Output is correct |
32 |
Correct |
399 ms |
43448 KB |
Output is correct |
33 |
Correct |
416 ms |
43100 KB |
Output is correct |
34 |
Correct |
318 ms |
30664 KB |
Output is correct |
35 |
Correct |
244 ms |
31216 KB |
Output is correct |
36 |
Correct |
417 ms |
43172 KB |
Output is correct |
37 |
Correct |
291 ms |
30664 KB |
Output is correct |
38 |
Correct |
294 ms |
30764 KB |
Output is correct |
39 |
Correct |
217 ms |
30508 KB |
Output is correct |
40 |
Correct |
262 ms |
30572 KB |
Output is correct |
41 |
Correct |
337 ms |
33600 KB |
Output is correct |
42 |
Correct |
10 ms |
14420 KB |
Output is correct |
43 |
Correct |
423 ms |
35804 KB |
Output is correct |
44 |
Correct |
425 ms |
37184 KB |
Output is correct |
45 |
Correct |
404 ms |
38804 KB |
Output is correct |
46 |
Correct |
364 ms |
37460 KB |
Output is correct |
47 |
Correct |
377 ms |
34060 KB |
Output is correct |
48 |
Correct |
289 ms |
33128 KB |
Output is correct |
49 |
Correct |
210 ms |
32352 KB |
Output is correct |
50 |
Correct |
227 ms |
26464 KB |
Output is correct |
51 |
Correct |
335 ms |
39124 KB |
Output is correct |
52 |
Correct |
294 ms |
33072 KB |
Output is correct |
53 |
Correct |
8 ms |
14420 KB |
Output is correct |
54 |
Correct |
8 ms |
14420 KB |
Output is correct |
55 |
Correct |
8 ms |
14420 KB |
Output is correct |
56 |
Correct |
11 ms |
14548 KB |
Output is correct |
57 |
Correct |
12 ms |
14548 KB |
Output is correct |
58 |
Correct |
11 ms |
14568 KB |
Output is correct |
59 |
Correct |
10 ms |
14516 KB |
Output is correct |
60 |
Correct |
9 ms |
14548 KB |
Output is correct |
61 |
Correct |
10 ms |
14548 KB |
Output is correct |
62 |
Correct |
10 ms |
14676 KB |
Output is correct |
63 |
Correct |
9 ms |
14676 KB |
Output is correct |
64 |
Correct |
12 ms |
14688 KB |
Output is correct |
65 |
Correct |
10 ms |
14548 KB |
Output is correct |
66 |
Correct |
9 ms |
14640 KB |
Output is correct |
67 |
Correct |
295 ms |
32504 KB |
Output is correct |
68 |
Correct |
264 ms |
31540 KB |
Output is correct |
69 |
Correct |
365 ms |
39264 KB |
Output is correct |
70 |
Correct |
461 ms |
40136 KB |
Output is correct |
71 |
Correct |
456 ms |
40464 KB |
Output is correct |
72 |
Correct |
353 ms |
31596 KB |
Output is correct |
73 |
Correct |
396 ms |
49364 KB |
Output is correct |
74 |
Correct |
277 ms |
33144 KB |
Output is correct |
75 |
Correct |
257 ms |
33116 KB |
Output is correct |
76 |
Correct |
307 ms |
33556 KB |
Output is correct |
77 |
Correct |
258 ms |
30696 KB |
Output is correct |
78 |
Correct |
304 ms |
30584 KB |
Output is correct |
79 |
Correct |
283 ms |
30696 KB |
Output is correct |
80 |
Correct |
222 ms |
30496 KB |
Output is correct |
81 |
Correct |
359 ms |
43204 KB |
Output is correct |
82 |
Correct |
422 ms |
43116 KB |
Output is correct |
83 |
Correct |
308 ms |
30736 KB |
Output is correct |
84 |
Correct |
258 ms |
31204 KB |
Output is correct |
85 |
Correct |
377 ms |
43232 KB |
Output is correct |
86 |
Correct |
319 ms |
30664 KB |
Output is correct |
87 |
Correct |
320 ms |
30760 KB |
Output is correct |
88 |
Correct |
297 ms |
30696 KB |
Output is correct |
89 |
Correct |
271 ms |
33700 KB |
Output is correct |
90 |
Correct |
402 ms |
35924 KB |
Output is correct |
91 |
Correct |
371 ms |
37148 KB |
Output is correct |
92 |
Correct |
395 ms |
38732 KB |
Output is correct |
93 |
Correct |
389 ms |
37468 KB |
Output is correct |
94 |
Correct |
336 ms |
34060 KB |
Output is correct |
95 |
Correct |
277 ms |
33092 KB |
Output is correct |
96 |
Correct |
208 ms |
32240 KB |
Output is correct |
97 |
Correct |
208 ms |
26424 KB |
Output is correct |
98 |
Correct |
310 ms |
39116 KB |
Output is correct |
99 |
Correct |
281 ms |
33360 KB |
Output is correct |
100 |
Correct |
113 ms |
19140 KB |
Output is correct |
101 |
Correct |
414 ms |
38324 KB |
Output is correct |
102 |
Correct |
323 ms |
30868 KB |
Output is correct |
103 |
Correct |
354 ms |
31320 KB |
Output is correct |
104 |
Correct |
385 ms |
34880 KB |
Output is correct |