#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<numeric>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<deque>
#include<cmath>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define ld long double
struct DSU{
vector<vector<int>> group;
vector<int> par;
vector<ll> sz, val;
int N;
DSU(int _N){
N = _N;
sz = vector<ll>(N+1);
val = vector<ll>(N+1);
par = vector<int>(N+1); iota(par.begin(), par.end(), 0);
group = vector<vector<int>>(N+1); for(int i = 1; i <= N; ++i)group[i].push_back(i);
}
int rep(int x){
if(par[x] == x)return x;
return par[x] = rep(par[x]);
}
void comb(int u, int v){
int pu = rep(u), pv = rep(v);
if(pu != pv){
if(val[pv] < sz[u]){
vector<int>().swap(group[pv]);
}
if((int)group[pu].size() > (int)group[pv].size()){
swap(pu, pv);
}
for(int elem : group[pu]){
group[pv].push_back(elem);
}
vector<int>().swap(group[pu]);
val[pv] += val[pu];
par[pu] = pv;
}
}
};
vector<int> adj[200005];
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N, M; cin >> N >> M;
DSU dsu(N);
vector<pair<int, int>> order;
for(int i = 1; i <= N; ++i){
int x; cin >> x;
dsu.val[i] = dsu.sz[i] = x;
order.push_back({x, i});
}
for(int i = 1; i <= M; ++i){
int u, v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
sort(order.begin(), order.end());
vector<bool> vis(N+1);
for(int i = 0; i < N; ++i){
int cur = order[i].second;
vis[cur] = 1;
for(int nx : adj[cur]){
if(vis[nx]){
dsu.comb(cur, nx);
}
}
}
vector<bool> answer(N+1);
for(int elem : dsu.group[dsu.rep(1)]){
answer[elem] = 1;
}
for(int i = 1; i <= N; ++i){
cout << answer[i];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5204 KB |
Output is correct |
5 |
Correct |
5 ms |
5288 KB |
Output is correct |
6 |
Correct |
4 ms |
5160 KB |
Output is correct |
7 |
Correct |
4 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5148 KB |
Output is correct |
9 |
Correct |
4 ms |
5228 KB |
Output is correct |
10 |
Correct |
4 ms |
5284 KB |
Output is correct |
11 |
Correct |
4 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5204 KB |
Output is correct |
13 |
Correct |
3 ms |
5160 KB |
Output is correct |
14 |
Correct |
4 ms |
5236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
145 ms |
27920 KB |
Output is correct |
4 |
Correct |
156 ms |
27928 KB |
Output is correct |
5 |
Correct |
161 ms |
27728 KB |
Output is correct |
6 |
Correct |
206 ms |
30832 KB |
Output is correct |
7 |
Correct |
201 ms |
30792 KB |
Output is correct |
8 |
Correct |
147 ms |
30356 KB |
Output is correct |
9 |
Correct |
145 ms |
30308 KB |
Output is correct |
10 |
Correct |
180 ms |
31064 KB |
Output is correct |
11 |
Correct |
147 ms |
31136 KB |
Output is correct |
12 |
Correct |
156 ms |
30340 KB |
Output is correct |
13 |
Correct |
138 ms |
30312 KB |
Output is correct |
14 |
Correct |
148 ms |
30324 KB |
Output is correct |
15 |
Correct |
162 ms |
30344 KB |
Output is correct |
16 |
Correct |
96 ms |
30080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
221 ms |
28292 KB |
Output is correct |
3 |
Correct |
213 ms |
29360 KB |
Output is correct |
4 |
Correct |
174 ms |
28984 KB |
Output is correct |
5 |
Correct |
140 ms |
30180 KB |
Output is correct |
6 |
Correct |
209 ms |
30624 KB |
Output is correct |
7 |
Correct |
163 ms |
30180 KB |
Output is correct |
8 |
Correct |
164 ms |
30204 KB |
Output is correct |
9 |
Correct |
97 ms |
30008 KB |
Output is correct |
10 |
Correct |
146 ms |
30228 KB |
Output is correct |
11 |
Correct |
163 ms |
31272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
221 ms |
28852 KB |
Output is correct |
3 |
Correct |
237 ms |
31396 KB |
Output is correct |
4 |
Correct |
248 ms |
32068 KB |
Output is correct |
5 |
Correct |
208 ms |
32448 KB |
Output is correct |
6 |
Correct |
184 ms |
30988 KB |
Output is correct |
7 |
Correct |
136 ms |
32100 KB |
Output is correct |
8 |
Correct |
103 ms |
30248 KB |
Output is correct |
9 |
Correct |
116 ms |
20092 KB |
Output is correct |
10 |
Correct |
176 ms |
33272 KB |
Output is correct |
11 |
Correct |
167 ms |
31268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5204 KB |
Output is correct |
5 |
Correct |
5 ms |
5288 KB |
Output is correct |
6 |
Correct |
4 ms |
5160 KB |
Output is correct |
7 |
Correct |
4 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5148 KB |
Output is correct |
9 |
Correct |
4 ms |
5228 KB |
Output is correct |
10 |
Correct |
4 ms |
5284 KB |
Output is correct |
11 |
Correct |
4 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5204 KB |
Output is correct |
13 |
Correct |
3 ms |
5160 KB |
Output is correct |
14 |
Correct |
4 ms |
5236 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
145 ms |
27920 KB |
Output is correct |
18 |
Correct |
156 ms |
27928 KB |
Output is correct |
19 |
Correct |
161 ms |
27728 KB |
Output is correct |
20 |
Correct |
206 ms |
30832 KB |
Output is correct |
21 |
Correct |
201 ms |
30792 KB |
Output is correct |
22 |
Correct |
147 ms |
30356 KB |
Output is correct |
23 |
Correct |
145 ms |
30308 KB |
Output is correct |
24 |
Correct |
180 ms |
31064 KB |
Output is correct |
25 |
Correct |
147 ms |
31136 KB |
Output is correct |
26 |
Correct |
156 ms |
30340 KB |
Output is correct |
27 |
Correct |
138 ms |
30312 KB |
Output is correct |
28 |
Correct |
148 ms |
30324 KB |
Output is correct |
29 |
Correct |
162 ms |
30344 KB |
Output is correct |
30 |
Correct |
96 ms |
30080 KB |
Output is correct |
31 |
Correct |
2 ms |
4948 KB |
Output is correct |
32 |
Correct |
221 ms |
28292 KB |
Output is correct |
33 |
Correct |
213 ms |
29360 KB |
Output is correct |
34 |
Correct |
174 ms |
28984 KB |
Output is correct |
35 |
Correct |
140 ms |
30180 KB |
Output is correct |
36 |
Correct |
209 ms |
30624 KB |
Output is correct |
37 |
Correct |
163 ms |
30180 KB |
Output is correct |
38 |
Correct |
164 ms |
30204 KB |
Output is correct |
39 |
Correct |
97 ms |
30008 KB |
Output is correct |
40 |
Correct |
146 ms |
30228 KB |
Output is correct |
41 |
Correct |
163 ms |
31272 KB |
Output is correct |
42 |
Correct |
2 ms |
4948 KB |
Output is correct |
43 |
Correct |
221 ms |
28852 KB |
Output is correct |
44 |
Correct |
237 ms |
31396 KB |
Output is correct |
45 |
Correct |
248 ms |
32068 KB |
Output is correct |
46 |
Correct |
208 ms |
32448 KB |
Output is correct |
47 |
Correct |
184 ms |
30988 KB |
Output is correct |
48 |
Correct |
136 ms |
32100 KB |
Output is correct |
49 |
Correct |
103 ms |
30248 KB |
Output is correct |
50 |
Correct |
116 ms |
20092 KB |
Output is correct |
51 |
Correct |
176 ms |
33272 KB |
Output is correct |
52 |
Correct |
167 ms |
31268 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 |
5160 KB |
Output is correct |
57 |
Correct |
5 ms |
5288 KB |
Output is correct |
58 |
Correct |
4 ms |
5180 KB |
Output is correct |
59 |
Correct |
4 ms |
5156 KB |
Output is correct |
60 |
Correct |
4 ms |
5136 KB |
Output is correct |
61 |
Correct |
4 ms |
5204 KB |
Output is correct |
62 |
Correct |
4 ms |
5284 KB |
Output is correct |
63 |
Correct |
5 ms |
5284 KB |
Output is correct |
64 |
Correct |
4 ms |
5284 KB |
Output is correct |
65 |
Correct |
4 ms |
5204 KB |
Output is correct |
66 |
Correct |
4 ms |
5204 KB |
Output is correct |
67 |
Correct |
160 ms |
30380 KB |
Output is correct |
68 |
Correct |
142 ms |
30152 KB |
Output is correct |
69 |
Correct |
197 ms |
30044 KB |
Output is correct |
70 |
Correct |
182 ms |
30596 KB |
Output is correct |
71 |
Correct |
189 ms |
30624 KB |
Output is correct |
72 |
Correct |
157 ms |
30300 KB |
Output is correct |
73 |
Correct |
149 ms |
30300 KB |
Output is correct |
74 |
Correct |
171 ms |
31016 KB |
Output is correct |
75 |
Correct |
151 ms |
30988 KB |
Output is correct |
76 |
Correct |
162 ms |
30212 KB |
Output is correct |
77 |
Correct |
149 ms |
30260 KB |
Output is correct |
78 |
Correct |
140 ms |
30128 KB |
Output is correct |
79 |
Correct |
156 ms |
30312 KB |
Output is correct |
80 |
Correct |
100 ms |
30828 KB |
Output is correct |
81 |
Correct |
215 ms |
30592 KB |
Output is correct |
82 |
Correct |
224 ms |
30744 KB |
Output is correct |
83 |
Correct |
183 ms |
30288 KB |
Output is correct |
84 |
Correct |
144 ms |
30172 KB |
Output is correct |
85 |
Correct |
217 ms |
32532 KB |
Output is correct |
86 |
Correct |
162 ms |
31976 KB |
Output is correct |
87 |
Correct |
176 ms |
32288 KB |
Output is correct |
88 |
Correct |
139 ms |
31640 KB |
Output is correct |
89 |
Correct |
179 ms |
31960 KB |
Output is correct |
90 |
Correct |
261 ms |
31188 KB |
Output is correct |
91 |
Correct |
240 ms |
31552 KB |
Output is correct |
92 |
Correct |
239 ms |
34320 KB |
Output is correct |
93 |
Correct |
219 ms |
34520 KB |
Output is correct |
94 |
Correct |
186 ms |
33076 KB |
Output is correct |
95 |
Correct |
154 ms |
32196 KB |
Output is correct |
96 |
Correct |
107 ms |
30364 KB |
Output is correct |
97 |
Correct |
121 ms |
20416 KB |
Output is correct |
98 |
Correct |
188 ms |
33868 KB |
Output is correct |
99 |
Correct |
170 ms |
31988 KB |
Output is correct |
100 |
Correct |
41 ms |
9468 KB |
Output is correct |
101 |
Correct |
246 ms |
33928 KB |
Output is correct |
102 |
Correct |
212 ms |
28824 KB |
Output is correct |
103 |
Correct |
196 ms |
29256 KB |
Output is correct |
104 |
Correct |
236 ms |
33084 KB |
Output is correct |