#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#define pii pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
using namespace std;
const int inf = 1e18;
void p(auto A){
for(auto e : A)cout << e << ' ';
cout << '\n';
}
void solve(){
int n, m; cin >> n >> m;
vector<int>A(n);
for(int i = 0; i< n; i++)cin >> A[i];
vector<vector<int>> g(n);
for(int i = 0; i< m; i++){
int c, d; cin >> c >> d; c--; d--;
g[c].pb(d);
g[d].pb(c);
}
vector<int> par(n, -1);
auto find = [&](auto&& self, int u)->int{
return par[u] < 0 ? u : par[u] = self(self, par[u]);
};
auto uni = [&](int u, int v)->bool{
u = find(find, u);
v = find(find, v);
if(u == v)return false;
par[u] += par[v];
par[v] = u;
return true;
};
vector<int> per(n);
iota(all(per), 0);
sort(all(per), [&](int i, int j)->bool{return A[i] < A[j];});
vector<vector<int>> tre(n);
vector<int> vis(n);
for(auto u : per){
vis[u] = 1;
for(auto v : g[u])if(vis[v])if(find(find, v) != u){
tre[u].pb(find(find,v));
uni(u, v);
}
}
vector<int>B = A;
for(auto u : per)for(auto v : tre[u])B[u] += B[v];
reverse(all(per));
vector<int> ans(n);
ans[per[0]] = 1;
for(auto u : per)for(auto v : tre[u])if(B[v] >= A[u])ans[v] = ans[u];
for(auto e : ans)cout << e;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin >> t;
while(t--)solve();
}
Compilation message
island.cpp:15:8: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
15 | void p(auto A){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
556 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
157 ms |
32236 KB |
Output is correct |
4 |
Correct |
165 ms |
33260 KB |
Output is correct |
5 |
Correct |
148 ms |
30144 KB |
Output is correct |
6 |
Correct |
157 ms |
31948 KB |
Output is correct |
7 |
Correct |
158 ms |
31064 KB |
Output is correct |
8 |
Correct |
191 ms |
32960 KB |
Output is correct |
9 |
Correct |
159 ms |
32460 KB |
Output is correct |
10 |
Correct |
104 ms |
29552 KB |
Output is correct |
11 |
Correct |
104 ms |
28988 KB |
Output is correct |
12 |
Correct |
159 ms |
31484 KB |
Output is correct |
13 |
Correct |
129 ms |
32460 KB |
Output is correct |
14 |
Correct |
138 ms |
33104 KB |
Output is correct |
15 |
Correct |
152 ms |
32596 KB |
Output is correct |
16 |
Correct |
98 ms |
32716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
196 ms |
32880 KB |
Output is correct |
3 |
Correct |
196 ms |
31996 KB |
Output is correct |
4 |
Correct |
148 ms |
33108 KB |
Output is correct |
5 |
Correct |
138 ms |
32588 KB |
Output is correct |
6 |
Correct |
200 ms |
31436 KB |
Output is correct |
7 |
Correct |
165 ms |
33356 KB |
Output is correct |
8 |
Correct |
169 ms |
33320 KB |
Output is correct |
9 |
Correct |
98 ms |
32460 KB |
Output is correct |
10 |
Correct |
157 ms |
30000 KB |
Output is correct |
11 |
Correct |
153 ms |
32224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
228 ms |
32292 KB |
Output is correct |
3 |
Correct |
194 ms |
33352 KB |
Output is correct |
4 |
Correct |
210 ms |
31488 KB |
Output is correct |
5 |
Correct |
167 ms |
35024 KB |
Output is correct |
6 |
Correct |
162 ms |
31880 KB |
Output is correct |
7 |
Correct |
111 ms |
31048 KB |
Output is correct |
8 |
Correct |
106 ms |
36308 KB |
Output is correct |
9 |
Correct |
110 ms |
19308 KB |
Output is correct |
10 |
Correct |
164 ms |
31720 KB |
Output is correct |
11 |
Correct |
168 ms |
30936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
556 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
157 ms |
32236 KB |
Output is correct |
18 |
Correct |
165 ms |
33260 KB |
Output is correct |
19 |
Correct |
148 ms |
30144 KB |
Output is correct |
20 |
Correct |
157 ms |
31948 KB |
Output is correct |
21 |
Correct |
158 ms |
31064 KB |
Output is correct |
22 |
Correct |
191 ms |
32960 KB |
Output is correct |
23 |
Correct |
159 ms |
32460 KB |
Output is correct |
24 |
Correct |
104 ms |
29552 KB |
Output is correct |
25 |
Correct |
104 ms |
28988 KB |
Output is correct |
26 |
Correct |
159 ms |
31484 KB |
Output is correct |
27 |
Correct |
129 ms |
32460 KB |
Output is correct |
28 |
Correct |
138 ms |
33104 KB |
Output is correct |
29 |
Correct |
152 ms |
32596 KB |
Output is correct |
30 |
Correct |
98 ms |
32716 KB |
Output is correct |
31 |
Correct |
0 ms |
320 KB |
Output is correct |
32 |
Correct |
196 ms |
32880 KB |
Output is correct |
33 |
Correct |
196 ms |
31996 KB |
Output is correct |
34 |
Correct |
148 ms |
33108 KB |
Output is correct |
35 |
Correct |
138 ms |
32588 KB |
Output is correct |
36 |
Correct |
200 ms |
31436 KB |
Output is correct |
37 |
Correct |
165 ms |
33356 KB |
Output is correct |
38 |
Correct |
169 ms |
33320 KB |
Output is correct |
39 |
Correct |
98 ms |
32460 KB |
Output is correct |
40 |
Correct |
157 ms |
30000 KB |
Output is correct |
41 |
Correct |
153 ms |
32224 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
228 ms |
32292 KB |
Output is correct |
44 |
Correct |
194 ms |
33352 KB |
Output is correct |
45 |
Correct |
210 ms |
31488 KB |
Output is correct |
46 |
Correct |
167 ms |
35024 KB |
Output is correct |
47 |
Correct |
162 ms |
31880 KB |
Output is correct |
48 |
Correct |
111 ms |
31048 KB |
Output is correct |
49 |
Correct |
106 ms |
36308 KB |
Output is correct |
50 |
Correct |
110 ms |
19308 KB |
Output is correct |
51 |
Correct |
164 ms |
31720 KB |
Output is correct |
52 |
Correct |
168 ms |
30936 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
340 KB |
Output is correct |
56 |
Correct |
2 ms |
584 KB |
Output is correct |
57 |
Correct |
2 ms |
596 KB |
Output is correct |
58 |
Correct |
1 ms |
468 KB |
Output is correct |
59 |
Correct |
2 ms |
468 KB |
Output is correct |
60 |
Correct |
2 ms |
468 KB |
Output is correct |
61 |
Correct |
1 ms |
596 KB |
Output is correct |
62 |
Correct |
2 ms |
596 KB |
Output is correct |
63 |
Correct |
2 ms |
596 KB |
Output is correct |
64 |
Correct |
1 ms |
596 KB |
Output is correct |
65 |
Correct |
2 ms |
596 KB |
Output is correct |
66 |
Correct |
2 ms |
596 KB |
Output is correct |
67 |
Correct |
149 ms |
33316 KB |
Output is correct |
68 |
Correct |
145 ms |
33596 KB |
Output is correct |
69 |
Correct |
160 ms |
30468 KB |
Output is correct |
70 |
Correct |
177 ms |
32364 KB |
Output is correct |
71 |
Correct |
166 ms |
30740 KB |
Output is correct |
72 |
Correct |
188 ms |
32364 KB |
Output is correct |
73 |
Correct |
166 ms |
32320 KB |
Output is correct |
74 |
Correct |
111 ms |
29864 KB |
Output is correct |
75 |
Correct |
140 ms |
30156 KB |
Output is correct |
76 |
Correct |
174 ms |
31808 KB |
Output is correct |
77 |
Correct |
158 ms |
32424 KB |
Output is correct |
78 |
Correct |
171 ms |
32332 KB |
Output is correct |
79 |
Correct |
163 ms |
33996 KB |
Output is correct |
80 |
Correct |
97 ms |
34728 KB |
Output is correct |
81 |
Correct |
238 ms |
31664 KB |
Output is correct |
82 |
Correct |
210 ms |
32424 KB |
Output is correct |
83 |
Correct |
165 ms |
31344 KB |
Output is correct |
84 |
Correct |
164 ms |
33260 KB |
Output is correct |
85 |
Correct |
230 ms |
34180 KB |
Output is correct |
86 |
Correct |
188 ms |
36156 KB |
Output is correct |
87 |
Correct |
175 ms |
36004 KB |
Output is correct |
88 |
Correct |
150 ms |
28820 KB |
Output is correct |
89 |
Correct |
155 ms |
29964 KB |
Output is correct |
90 |
Correct |
210 ms |
30596 KB |
Output is correct |
91 |
Correct |
231 ms |
34212 KB |
Output is correct |
92 |
Correct |
232 ms |
34844 KB |
Output is correct |
93 |
Correct |
198 ms |
33996 KB |
Output is correct |
94 |
Correct |
181 ms |
31116 KB |
Output is correct |
95 |
Correct |
116 ms |
31548 KB |
Output is correct |
96 |
Correct |
103 ms |
35128 KB |
Output is correct |
97 |
Correct |
115 ms |
18504 KB |
Output is correct |
98 |
Correct |
163 ms |
30892 KB |
Output is correct |
99 |
Correct |
149 ms |
31500 KB |
Output is correct |
100 |
Correct |
48 ms |
6872 KB |
Output is correct |
101 |
Correct |
223 ms |
34728 KB |
Output is correct |
102 |
Correct |
154 ms |
26780 KB |
Output is correct |
103 |
Correct |
219 ms |
26356 KB |
Output is correct |
104 |
Correct |
239 ms |
30240 KB |
Output is correct |