#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, cnt[N];
struct DSU{
int par[N];
long long sum[N];
vector<int> nodes[N];
DSU(){
for(int i = 1; i < N; i++){
par[i] = i;
nodes[i] = {i};
}
}
int setfind(int a){
if(par[a] == a) return a;
else return par[a] = setfind(par[a]);
}
void setunion(int a, int b){
a = setfind(a), b = setfind(b);
if(a != b){
if(nodes[b].size() > nodes[a].size()) swap(a, b);
par[b] = par[a];
sum[a] += sum[b];
for(auto x : nodes[b]) nodes[a].push_back(x);
nodes[b].clear();
}
}
};
DSU dsu;
pair<int, int> arr[N];
vector<int> graph[N];
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> cnt[i];
arr[i] = {cnt[i], i};
dsu.sum[i] = cnt[i];
}
sort(arr + 1, arr + n + 1);
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
for(int i = 1; i <= n; i++){
int v = arr[i].second;
for(auto e : graph[v]){
if(cnt[e] <= cnt[v] && dsu.setfind(v) != dsu.setfind(e)){
if(dsu.sum[dsu.setfind(e)] < cnt[v]) dsu.nodes[dsu.setfind(e)].clear();
dsu.setunion(v, e);
}
}
}
string ans(n, '0');
for(auto x : dsu.nodes[dsu.setfind(arr[n].second)]) ans[x - 1] = '1';
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
16724 KB |
Output is correct |
2 |
Correct |
15 ms |
16776 KB |
Output is correct |
3 |
Correct |
14 ms |
16724 KB |
Output is correct |
4 |
Correct |
17 ms |
16848 KB |
Output is correct |
5 |
Correct |
16 ms |
16924 KB |
Output is correct |
6 |
Correct |
17 ms |
16796 KB |
Output is correct |
7 |
Correct |
19 ms |
16852 KB |
Output is correct |
8 |
Correct |
17 ms |
16904 KB |
Output is correct |
9 |
Correct |
16 ms |
16924 KB |
Output is correct |
10 |
Correct |
16 ms |
16896 KB |
Output is correct |
11 |
Correct |
17 ms |
16852 KB |
Output is correct |
12 |
Correct |
17 ms |
16920 KB |
Output is correct |
13 |
Correct |
17 ms |
16852 KB |
Output is correct |
14 |
Correct |
17 ms |
16928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
16724 KB |
Output is correct |
2 |
Correct |
14 ms |
16784 KB |
Output is correct |
3 |
Correct |
144 ms |
32580 KB |
Output is correct |
4 |
Correct |
144 ms |
31248 KB |
Output is correct |
5 |
Correct |
179 ms |
34020 KB |
Output is correct |
6 |
Correct |
199 ms |
34492 KB |
Output is correct |
7 |
Correct |
176 ms |
34328 KB |
Output is correct |
8 |
Correct |
156 ms |
32480 KB |
Output is correct |
9 |
Correct |
170 ms |
35640 KB |
Output is correct |
10 |
Correct |
110 ms |
31680 KB |
Output is correct |
11 |
Correct |
144 ms |
32664 KB |
Output is correct |
12 |
Correct |
157 ms |
31436 KB |
Output is correct |
13 |
Correct |
134 ms |
30996 KB |
Output is correct |
14 |
Correct |
132 ms |
31244 KB |
Output is correct |
15 |
Correct |
144 ms |
32456 KB |
Output is correct |
16 |
Correct |
84 ms |
31700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
16724 KB |
Output is correct |
2 |
Correct |
207 ms |
35252 KB |
Output is correct |
3 |
Correct |
213 ms |
35396 KB |
Output is correct |
4 |
Correct |
160 ms |
32500 KB |
Output is correct |
5 |
Correct |
148 ms |
30972 KB |
Output is correct |
6 |
Correct |
204 ms |
35504 KB |
Output is correct |
7 |
Correct |
157 ms |
32572 KB |
Output is correct |
8 |
Correct |
159 ms |
32568 KB |
Output is correct |
9 |
Correct |
86 ms |
31684 KB |
Output is correct |
10 |
Correct |
146 ms |
31632 KB |
Output is correct |
11 |
Correct |
166 ms |
31384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
16724 KB |
Output is correct |
2 |
Correct |
233 ms |
33236 KB |
Output is correct |
3 |
Correct |
214 ms |
33616 KB |
Output is correct |
4 |
Correct |
229 ms |
34688 KB |
Output is correct |
5 |
Correct |
219 ms |
35572 KB |
Output is correct |
6 |
Correct |
202 ms |
33440 KB |
Output is correct |
7 |
Correct |
127 ms |
33576 KB |
Output is correct |
8 |
Correct |
85 ms |
31380 KB |
Output is correct |
9 |
Correct |
112 ms |
26316 KB |
Output is correct |
10 |
Correct |
213 ms |
34824 KB |
Output is correct |
11 |
Correct |
171 ms |
31300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
16724 KB |
Output is correct |
2 |
Correct |
15 ms |
16776 KB |
Output is correct |
3 |
Correct |
14 ms |
16724 KB |
Output is correct |
4 |
Correct |
17 ms |
16848 KB |
Output is correct |
5 |
Correct |
16 ms |
16924 KB |
Output is correct |
6 |
Correct |
17 ms |
16796 KB |
Output is correct |
7 |
Correct |
19 ms |
16852 KB |
Output is correct |
8 |
Correct |
17 ms |
16904 KB |
Output is correct |
9 |
Correct |
16 ms |
16924 KB |
Output is correct |
10 |
Correct |
16 ms |
16896 KB |
Output is correct |
11 |
Correct |
17 ms |
16852 KB |
Output is correct |
12 |
Correct |
17 ms |
16920 KB |
Output is correct |
13 |
Correct |
17 ms |
16852 KB |
Output is correct |
14 |
Correct |
17 ms |
16928 KB |
Output is correct |
15 |
Correct |
13 ms |
16724 KB |
Output is correct |
16 |
Correct |
14 ms |
16784 KB |
Output is correct |
17 |
Correct |
144 ms |
32580 KB |
Output is correct |
18 |
Correct |
144 ms |
31248 KB |
Output is correct |
19 |
Correct |
179 ms |
34020 KB |
Output is correct |
20 |
Correct |
199 ms |
34492 KB |
Output is correct |
21 |
Correct |
176 ms |
34328 KB |
Output is correct |
22 |
Correct |
156 ms |
32480 KB |
Output is correct |
23 |
Correct |
170 ms |
35640 KB |
Output is correct |
24 |
Correct |
110 ms |
31680 KB |
Output is correct |
25 |
Correct |
144 ms |
32664 KB |
Output is correct |
26 |
Correct |
157 ms |
31436 KB |
Output is correct |
27 |
Correct |
134 ms |
30996 KB |
Output is correct |
28 |
Correct |
132 ms |
31244 KB |
Output is correct |
29 |
Correct |
144 ms |
32456 KB |
Output is correct |
30 |
Correct |
84 ms |
31700 KB |
Output is correct |
31 |
Correct |
13 ms |
16724 KB |
Output is correct |
32 |
Correct |
207 ms |
35252 KB |
Output is correct |
33 |
Correct |
213 ms |
35396 KB |
Output is correct |
34 |
Correct |
160 ms |
32500 KB |
Output is correct |
35 |
Correct |
148 ms |
30972 KB |
Output is correct |
36 |
Correct |
204 ms |
35504 KB |
Output is correct |
37 |
Correct |
157 ms |
32572 KB |
Output is correct |
38 |
Correct |
159 ms |
32568 KB |
Output is correct |
39 |
Correct |
86 ms |
31684 KB |
Output is correct |
40 |
Correct |
146 ms |
31632 KB |
Output is correct |
41 |
Correct |
166 ms |
31384 KB |
Output is correct |
42 |
Correct |
16 ms |
16724 KB |
Output is correct |
43 |
Correct |
233 ms |
33236 KB |
Output is correct |
44 |
Correct |
214 ms |
33616 KB |
Output is correct |
45 |
Correct |
229 ms |
34688 KB |
Output is correct |
46 |
Correct |
219 ms |
35572 KB |
Output is correct |
47 |
Correct |
202 ms |
33440 KB |
Output is correct |
48 |
Correct |
127 ms |
33576 KB |
Output is correct |
49 |
Correct |
85 ms |
31380 KB |
Output is correct |
50 |
Correct |
112 ms |
26316 KB |
Output is correct |
51 |
Correct |
213 ms |
34824 KB |
Output is correct |
52 |
Correct |
171 ms |
31300 KB |
Output is correct |
53 |
Correct |
14 ms |
16780 KB |
Output is correct |
54 |
Correct |
14 ms |
16660 KB |
Output is correct |
55 |
Correct |
14 ms |
16784 KB |
Output is correct |
56 |
Correct |
18 ms |
16852 KB |
Output is correct |
57 |
Correct |
17 ms |
16852 KB |
Output is correct |
58 |
Correct |
17 ms |
16812 KB |
Output is correct |
59 |
Correct |
17 ms |
16880 KB |
Output is correct |
60 |
Correct |
17 ms |
16844 KB |
Output is correct |
61 |
Correct |
17 ms |
16808 KB |
Output is correct |
62 |
Correct |
17 ms |
16840 KB |
Output is correct |
63 |
Correct |
17 ms |
16852 KB |
Output is correct |
64 |
Correct |
17 ms |
16852 KB |
Output is correct |
65 |
Correct |
19 ms |
16924 KB |
Output is correct |
66 |
Correct |
17 ms |
16852 KB |
Output is correct |
67 |
Correct |
137 ms |
32620 KB |
Output is correct |
68 |
Correct |
134 ms |
31248 KB |
Output is correct |
69 |
Correct |
180 ms |
33976 KB |
Output is correct |
70 |
Correct |
226 ms |
34596 KB |
Output is correct |
71 |
Correct |
201 ms |
34404 KB |
Output is correct |
72 |
Correct |
164 ms |
32568 KB |
Output is correct |
73 |
Correct |
190 ms |
35572 KB |
Output is correct |
74 |
Correct |
126 ms |
31728 KB |
Output is correct |
75 |
Correct |
125 ms |
32552 KB |
Output is correct |
76 |
Correct |
177 ms |
31436 KB |
Output is correct |
77 |
Correct |
117 ms |
30988 KB |
Output is correct |
78 |
Correct |
142 ms |
31280 KB |
Output is correct |
79 |
Correct |
146 ms |
32484 KB |
Output is correct |
80 |
Correct |
83 ms |
31704 KB |
Output is correct |
81 |
Correct |
213 ms |
35396 KB |
Output is correct |
82 |
Correct |
192 ms |
35388 KB |
Output is correct |
83 |
Correct |
143 ms |
32584 KB |
Output is correct |
84 |
Correct |
143 ms |
30980 KB |
Output is correct |
85 |
Correct |
191 ms |
35400 KB |
Output is correct |
86 |
Correct |
151 ms |
32564 KB |
Output is correct |
87 |
Correct |
149 ms |
32476 KB |
Output is correct |
88 |
Correct |
147 ms |
31420 KB |
Output is correct |
89 |
Correct |
175 ms |
31364 KB |
Output is correct |
90 |
Correct |
227 ms |
33252 KB |
Output is correct |
91 |
Correct |
228 ms |
33760 KB |
Output is correct |
92 |
Correct |
234 ms |
34756 KB |
Output is correct |
93 |
Correct |
219 ms |
35520 KB |
Output is correct |
94 |
Correct |
213 ms |
33488 KB |
Output is correct |
95 |
Correct |
130 ms |
33592 KB |
Output is correct |
96 |
Correct |
95 ms |
31280 KB |
Output is correct |
97 |
Correct |
123 ms |
26264 KB |
Output is correct |
98 |
Correct |
208 ms |
34804 KB |
Output is correct |
99 |
Correct |
156 ms |
31380 KB |
Output is correct |
100 |
Correct |
51 ms |
21008 KB |
Output is correct |
101 |
Correct |
213 ms |
33980 KB |
Output is correct |
102 |
Correct |
182 ms |
30580 KB |
Output is correct |
103 |
Correct |
193 ms |
30424 KB |
Output is correct |
104 |
Correct |
205 ms |
32716 KB |
Output is correct |