#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++)
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14432 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 |
14580 KB |
Output is correct |
6 |
Correct |
9 ms |
14596 KB |
Output is correct |
7 |
Correct |
9 ms |
14572 KB |
Output is correct |
8 |
Correct |
10 ms |
14548 KB |
Output is correct |
9 |
Correct |
9 ms |
14548 KB |
Output is correct |
10 |
Correct |
10 ms |
14700 KB |
Output is correct |
11 |
Correct |
9 ms |
14592 KB |
Output is correct |
12 |
Correct |
10 ms |
14676 KB |
Output is correct |
13 |
Correct |
9 ms |
14580 KB |
Output is correct |
14 |
Correct |
9 ms |
14608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
292 ms |
36488 KB |
Output is correct |
4 |
Correct |
262 ms |
34576 KB |
Output is correct |
5 |
Correct |
337 ms |
43248 KB |
Output is correct |
6 |
Correct |
340 ms |
44084 KB |
Output is correct |
7 |
Correct |
362 ms |
44508 KB |
Output is correct |
8 |
Correct |
312 ms |
35512 KB |
Output is correct |
9 |
Correct |
317 ms |
53456 KB |
Output is correct |
10 |
Correct |
251 ms |
36688 KB |
Output is correct |
11 |
Correct |
245 ms |
36604 KB |
Output is correct |
12 |
Correct |
259 ms |
36576 KB |
Output is correct |
13 |
Correct |
226 ms |
33480 KB |
Output is correct |
14 |
Correct |
242 ms |
33736 KB |
Output is correct |
15 |
Correct |
277 ms |
34612 KB |
Output is correct |
16 |
Correct |
204 ms |
34268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14548 KB |
Output is correct |
2 |
Correct |
356 ms |
47128 KB |
Output is correct |
3 |
Correct |
360 ms |
47104 KB |
Output is correct |
4 |
Correct |
288 ms |
34632 KB |
Output is correct |
5 |
Correct |
244 ms |
34108 KB |
Output is correct |
6 |
Correct |
362 ms |
47140 KB |
Output is correct |
7 |
Correct |
292 ms |
34644 KB |
Output is correct |
8 |
Correct |
295 ms |
34616 KB |
Output is correct |
9 |
Correct |
207 ms |
34204 KB |
Output is correct |
10 |
Correct |
259 ms |
34376 KB |
Output is correct |
11 |
Correct |
286 ms |
36596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
364 ms |
39760 KB |
Output is correct |
3 |
Correct |
363 ms |
41160 KB |
Output is correct |
4 |
Correct |
387 ms |
42704 KB |
Output is correct |
5 |
Correct |
362 ms |
41536 KB |
Output is correct |
6 |
Correct |
330 ms |
38100 KB |
Output is correct |
7 |
Correct |
272 ms |
37124 KB |
Output is correct |
8 |
Correct |
196 ms |
35420 KB |
Output is correct |
9 |
Correct |
196 ms |
29096 KB |
Output is correct |
10 |
Correct |
306 ms |
41936 KB |
Output is correct |
11 |
Correct |
266 ms |
36144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14432 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 |
14580 KB |
Output is correct |
6 |
Correct |
9 ms |
14596 KB |
Output is correct |
7 |
Correct |
9 ms |
14572 KB |
Output is correct |
8 |
Correct |
10 ms |
14548 KB |
Output is correct |
9 |
Correct |
9 ms |
14548 KB |
Output is correct |
10 |
Correct |
10 ms |
14700 KB |
Output is correct |
11 |
Correct |
9 ms |
14592 KB |
Output is correct |
12 |
Correct |
10 ms |
14676 KB |
Output is correct |
13 |
Correct |
9 ms |
14580 KB |
Output is correct |
14 |
Correct |
9 ms |
14608 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 |
36488 KB |
Output is correct |
18 |
Correct |
262 ms |
34576 KB |
Output is correct |
19 |
Correct |
337 ms |
43248 KB |
Output is correct |
20 |
Correct |
340 ms |
44084 KB |
Output is correct |
21 |
Correct |
362 ms |
44508 KB |
Output is correct |
22 |
Correct |
312 ms |
35512 KB |
Output is correct |
23 |
Correct |
317 ms |
53456 KB |
Output is correct |
24 |
Correct |
251 ms |
36688 KB |
Output is correct |
25 |
Correct |
245 ms |
36604 KB |
Output is correct |
26 |
Correct |
259 ms |
36576 KB |
Output is correct |
27 |
Correct |
226 ms |
33480 KB |
Output is correct |
28 |
Correct |
242 ms |
33736 KB |
Output is correct |
29 |
Correct |
277 ms |
34612 KB |
Output is correct |
30 |
Correct |
204 ms |
34268 KB |
Output is correct |
31 |
Correct |
8 ms |
14548 KB |
Output is correct |
32 |
Correct |
356 ms |
47128 KB |
Output is correct |
33 |
Correct |
360 ms |
47104 KB |
Output is correct |
34 |
Correct |
288 ms |
34632 KB |
Output is correct |
35 |
Correct |
244 ms |
34108 KB |
Output is correct |
36 |
Correct |
362 ms |
47140 KB |
Output is correct |
37 |
Correct |
292 ms |
34644 KB |
Output is correct |
38 |
Correct |
295 ms |
34616 KB |
Output is correct |
39 |
Correct |
207 ms |
34204 KB |
Output is correct |
40 |
Correct |
259 ms |
34376 KB |
Output is correct |
41 |
Correct |
286 ms |
36596 KB |
Output is correct |
42 |
Correct |
7 ms |
14420 KB |
Output is correct |
43 |
Correct |
364 ms |
39760 KB |
Output is correct |
44 |
Correct |
363 ms |
41160 KB |
Output is correct |
45 |
Correct |
387 ms |
42704 KB |
Output is correct |
46 |
Correct |
362 ms |
41536 KB |
Output is correct |
47 |
Correct |
330 ms |
38100 KB |
Output is correct |
48 |
Correct |
272 ms |
37124 KB |
Output is correct |
49 |
Correct |
196 ms |
35420 KB |
Output is correct |
50 |
Correct |
196 ms |
29096 KB |
Output is correct |
51 |
Correct |
306 ms |
41936 KB |
Output is correct |
52 |
Correct |
266 ms |
36144 KB |
Output is correct |
53 |
Correct |
7 ms |
14436 KB |
Output is correct |
54 |
Correct |
8 ms |
14396 KB |
Output is correct |
55 |
Correct |
9 ms |
14420 KB |
Output is correct |
56 |
Correct |
10 ms |
14540 KB |
Output is correct |
57 |
Correct |
10 ms |
14576 KB |
Output is correct |
58 |
Correct |
8 ms |
14548 KB |
Output is correct |
59 |
Correct |
10 ms |
14584 KB |
Output is correct |
60 |
Correct |
9 ms |
14488 KB |
Output is correct |
61 |
Correct |
9 ms |
14548 KB |
Output is correct |
62 |
Correct |
10 ms |
14700 KB |
Output is correct |
63 |
Correct |
9 ms |
14704 KB |
Output is correct |
64 |
Correct |
9 ms |
14676 KB |
Output is correct |
65 |
Correct |
9 ms |
14584 KB |
Output is correct |
66 |
Correct |
9 ms |
14548 KB |
Output is correct |
67 |
Correct |
286 ms |
36408 KB |
Output is correct |
68 |
Correct |
262 ms |
34504 KB |
Output is correct |
69 |
Correct |
315 ms |
43192 KB |
Output is correct |
70 |
Correct |
342 ms |
44216 KB |
Output is correct |
71 |
Correct |
332 ms |
44468 KB |
Output is correct |
72 |
Correct |
315 ms |
35624 KB |
Output is correct |
73 |
Correct |
312 ms |
53336 KB |
Output is correct |
74 |
Correct |
251 ms |
36668 KB |
Output is correct |
75 |
Correct |
242 ms |
36520 KB |
Output is correct |
76 |
Correct |
267 ms |
36516 KB |
Output is correct |
77 |
Correct |
231 ms |
33592 KB |
Output is correct |
78 |
Correct |
236 ms |
33736 KB |
Output is correct |
79 |
Correct |
262 ms |
34680 KB |
Output is correct |
80 |
Correct |
203 ms |
34292 KB |
Output is correct |
81 |
Correct |
368 ms |
47132 KB |
Output is correct |
82 |
Correct |
366 ms |
47236 KB |
Output is correct |
83 |
Correct |
293 ms |
34580 KB |
Output is correct |
84 |
Correct |
272 ms |
34192 KB |
Output is correct |
85 |
Correct |
356 ms |
47232 KB |
Output is correct |
86 |
Correct |
293 ms |
34620 KB |
Output is correct |
87 |
Correct |
273 ms |
34620 KB |
Output is correct |
88 |
Correct |
257 ms |
34360 KB |
Output is correct |
89 |
Correct |
271 ms |
36696 KB |
Output is correct |
90 |
Correct |
409 ms |
39808 KB |
Output is correct |
91 |
Correct |
413 ms |
41124 KB |
Output is correct |
92 |
Correct |
465 ms |
42668 KB |
Output is correct |
93 |
Correct |
387 ms |
41404 KB |
Output is correct |
94 |
Correct |
352 ms |
38144 KB |
Output is correct |
95 |
Correct |
265 ms |
37040 KB |
Output is correct |
96 |
Correct |
198 ms |
35440 KB |
Output is correct |
97 |
Correct |
228 ms |
29060 KB |
Output is correct |
98 |
Correct |
313 ms |
41996 KB |
Output is correct |
99 |
Correct |
280 ms |
36048 KB |
Output is correct |
100 |
Correct |
107 ms |
20852 KB |
Output is correct |
101 |
Correct |
389 ms |
42256 KB |
Output is correct |
102 |
Correct |
293 ms |
34756 KB |
Output is correct |
103 |
Correct |
330 ms |
35256 KB |
Output is correct |
104 |
Correct |
408 ms |
38848 KB |
Output is correct |