#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 2e5 + 5;
int n, m, P;
ll S[maxn];
int par[maxn];
ll M[maxn];
vector<int> W[maxn];
vector<pair<pair<ll, ll>, ii>> E;
int ans[maxn];
int find(int x) {return (par[x] == x) ? x : par[x] = find(par[x]);}
void merge(int x, int y) {
x = find(x), y = find(y);
if(x == y) return;
if(W[x].size() < W[y].size())
swap(x, y);
if(S[x] < M[y]) W[x].clear();
if(S[y] < M[x]) W[y].clear();
for(int i : W[y])
W[x].pb(i);
par[y] = x;
M[x] = max(M[x], M[y]);
S[x] += S[y];
P = x;
}
int main() {
scanf("%d%d", &n, &m);
for(int i = 0;i < n;i++)
scanf("%lld", S + i);
for(int i = 0;i < m;i++) {
int x, y;
scanf("%d%d", &x, &y);
x--, y--;
if(S[x] < S[y]) swap(x, y);
E.pb({{S[x], S[y]}, {x, y}});
}
sort(all(E));
for(int i = 0;i < n;i++)
par[i] = i, M[i] = S[i], W[i].pb(i);
for(auto p : E)
merge(p.y.x, p.y.y);
for(int i : W[P]) ans[i] = 1;
for(int i = 0;i < n;i++)
printf("%d", ans[i]);
printf("\n");
return 0;
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
island.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf("%lld", S + i);
| ~~~~~^~~~~~~~~~~~~~~
island.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%d%d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
6 ms |
5204 KB |
Output is correct |
6 |
Correct |
4 ms |
5076 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5076 KB |
Output is correct |
10 |
Correct |
6 ms |
5204 KB |
Output is correct |
11 |
Correct |
4 ms |
5204 KB |
Output is correct |
12 |
Correct |
4 ms |
5204 KB |
Output is correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Correct |
4 ms |
5076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
125 ms |
22332 KB |
Output is correct |
4 |
Correct |
120 ms |
21816 KB |
Output is correct |
5 |
Correct |
133 ms |
23440 KB |
Output is correct |
6 |
Correct |
137 ms |
24076 KB |
Output is correct |
7 |
Correct |
135 ms |
24044 KB |
Output is correct |
8 |
Correct |
135 ms |
22576 KB |
Output is correct |
9 |
Correct |
124 ms |
25508 KB |
Output is correct |
10 |
Correct |
117 ms |
19976 KB |
Output is correct |
11 |
Correct |
124 ms |
22552 KB |
Output is correct |
12 |
Correct |
137 ms |
21272 KB |
Output is correct |
13 |
Correct |
119 ms |
21880 KB |
Output is correct |
14 |
Correct |
119 ms |
21764 KB |
Output is correct |
15 |
Correct |
118 ms |
22572 KB |
Output is correct |
16 |
Correct |
89 ms |
22388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
160 ms |
24732 KB |
Output is correct |
3 |
Correct |
161 ms |
24884 KB |
Output is correct |
4 |
Correct |
123 ms |
22560 KB |
Output is correct |
5 |
Correct |
114 ms |
21596 KB |
Output is correct |
6 |
Correct |
156 ms |
24716 KB |
Output is correct |
7 |
Correct |
123 ms |
22576 KB |
Output is correct |
8 |
Correct |
127 ms |
22696 KB |
Output is correct |
9 |
Correct |
91 ms |
22496 KB |
Output is correct |
10 |
Correct |
125 ms |
21720 KB |
Output is correct |
11 |
Correct |
142 ms |
22400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
163 ms |
22536 KB |
Output is correct |
3 |
Correct |
153 ms |
23024 KB |
Output is correct |
4 |
Correct |
170 ms |
23940 KB |
Output is correct |
5 |
Correct |
182 ms |
25396 KB |
Output is correct |
6 |
Correct |
168 ms |
23236 KB |
Output is correct |
7 |
Correct |
121 ms |
22524 KB |
Output is correct |
8 |
Correct |
111 ms |
21744 KB |
Output is correct |
9 |
Correct |
106 ms |
15980 KB |
Output is correct |
10 |
Correct |
154 ms |
25360 KB |
Output is correct |
11 |
Correct |
177 ms |
22600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
6 ms |
5204 KB |
Output is correct |
6 |
Correct |
4 ms |
5076 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5076 KB |
Output is correct |
10 |
Correct |
6 ms |
5204 KB |
Output is correct |
11 |
Correct |
4 ms |
5204 KB |
Output is correct |
12 |
Correct |
4 ms |
5204 KB |
Output is correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Correct |
4 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
125 ms |
22332 KB |
Output is correct |
18 |
Correct |
120 ms |
21816 KB |
Output is correct |
19 |
Correct |
133 ms |
23440 KB |
Output is correct |
20 |
Correct |
137 ms |
24076 KB |
Output is correct |
21 |
Correct |
135 ms |
24044 KB |
Output is correct |
22 |
Correct |
135 ms |
22576 KB |
Output is correct |
23 |
Correct |
124 ms |
25508 KB |
Output is correct |
24 |
Correct |
117 ms |
19976 KB |
Output is correct |
25 |
Correct |
124 ms |
22552 KB |
Output is correct |
26 |
Correct |
137 ms |
21272 KB |
Output is correct |
27 |
Correct |
119 ms |
21880 KB |
Output is correct |
28 |
Correct |
119 ms |
21764 KB |
Output is correct |
29 |
Correct |
118 ms |
22572 KB |
Output is correct |
30 |
Correct |
89 ms |
22388 KB |
Output is correct |
31 |
Correct |
3 ms |
4948 KB |
Output is correct |
32 |
Correct |
160 ms |
24732 KB |
Output is correct |
33 |
Correct |
161 ms |
24884 KB |
Output is correct |
34 |
Correct |
123 ms |
22560 KB |
Output is correct |
35 |
Correct |
114 ms |
21596 KB |
Output is correct |
36 |
Correct |
156 ms |
24716 KB |
Output is correct |
37 |
Correct |
123 ms |
22576 KB |
Output is correct |
38 |
Correct |
127 ms |
22696 KB |
Output is correct |
39 |
Correct |
91 ms |
22496 KB |
Output is correct |
40 |
Correct |
125 ms |
21720 KB |
Output is correct |
41 |
Correct |
142 ms |
22400 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
163 ms |
22536 KB |
Output is correct |
44 |
Correct |
153 ms |
23024 KB |
Output is correct |
45 |
Correct |
170 ms |
23940 KB |
Output is correct |
46 |
Correct |
182 ms |
25396 KB |
Output is correct |
47 |
Correct |
168 ms |
23236 KB |
Output is correct |
48 |
Correct |
121 ms |
22524 KB |
Output is correct |
49 |
Correct |
111 ms |
21744 KB |
Output is correct |
50 |
Correct |
106 ms |
15980 KB |
Output is correct |
51 |
Correct |
154 ms |
25360 KB |
Output is correct |
52 |
Correct |
177 ms |
22600 KB |
Output is correct |
53 |
Correct |
3 ms |
4948 KB |
Output is correct |
54 |
Correct |
3 ms |
4948 KB |
Output is correct |
55 |
Correct |
3 ms |
4948 KB |
Output is correct |
56 |
Correct |
4 ms |
5076 KB |
Output is correct |
57 |
Correct |
4 ms |
5076 KB |
Output is correct |
58 |
Correct |
4 ms |
5076 KB |
Output is correct |
59 |
Correct |
4 ms |
5076 KB |
Output is correct |
60 |
Correct |
4 ms |
5076 KB |
Output is correct |
61 |
Correct |
5 ms |
5064 KB |
Output is correct |
62 |
Correct |
4 ms |
5204 KB |
Output is correct |
63 |
Correct |
4 ms |
5204 KB |
Output is correct |
64 |
Correct |
4 ms |
5204 KB |
Output is correct |
65 |
Correct |
4 ms |
5076 KB |
Output is correct |
66 |
Correct |
4 ms |
5076 KB |
Output is correct |
67 |
Correct |
129 ms |
22360 KB |
Output is correct |
68 |
Correct |
128 ms |
21836 KB |
Output is correct |
69 |
Correct |
133 ms |
23468 KB |
Output is correct |
70 |
Correct |
140 ms |
24060 KB |
Output is correct |
71 |
Correct |
143 ms |
24092 KB |
Output is correct |
72 |
Correct |
153 ms |
22660 KB |
Output is correct |
73 |
Correct |
159 ms |
25492 KB |
Output is correct |
74 |
Correct |
127 ms |
20040 KB |
Output is correct |
75 |
Correct |
120 ms |
22552 KB |
Output is correct |
76 |
Correct |
141 ms |
21288 KB |
Output is correct |
77 |
Correct |
123 ms |
21804 KB |
Output is correct |
78 |
Correct |
114 ms |
21800 KB |
Output is correct |
79 |
Correct |
119 ms |
22820 KB |
Output is correct |
80 |
Correct |
89 ms |
22440 KB |
Output is correct |
81 |
Correct |
156 ms |
24808 KB |
Output is correct |
82 |
Correct |
155 ms |
24924 KB |
Output is correct |
83 |
Correct |
124 ms |
22604 KB |
Output is correct |
84 |
Correct |
113 ms |
21624 KB |
Output is correct |
85 |
Correct |
164 ms |
24792 KB |
Output is correct |
86 |
Correct |
117 ms |
22568 KB |
Output is correct |
87 |
Correct |
123 ms |
22760 KB |
Output is correct |
88 |
Correct |
121 ms |
21668 KB |
Output is correct |
89 |
Correct |
150 ms |
22476 KB |
Output is correct |
90 |
Correct |
156 ms |
22612 KB |
Output is correct |
91 |
Correct |
170 ms |
23144 KB |
Output is correct |
92 |
Correct |
155 ms |
23940 KB |
Output is correct |
93 |
Correct |
183 ms |
25384 KB |
Output is correct |
94 |
Correct |
157 ms |
23208 KB |
Output is correct |
95 |
Correct |
126 ms |
22568 KB |
Output is correct |
96 |
Correct |
110 ms |
21676 KB |
Output is correct |
97 |
Correct |
105 ms |
16028 KB |
Output is correct |
98 |
Correct |
163 ms |
25324 KB |
Output is correct |
99 |
Correct |
158 ms |
22452 KB |
Output is correct |
100 |
Correct |
66 ms |
11332 KB |
Output is correct |
101 |
Correct |
153 ms |
23284 KB |
Output is correct |
102 |
Correct |
133 ms |
20464 KB |
Output is correct |
103 |
Correct |
136 ms |
20072 KB |
Output is correct |
104 |
Correct |
160 ms |
22064 KB |
Output is correct |