#include<bits/stdc++.h>
using namespace std;
// #pragma GCC optimize (03)
#define int long long
#define ll long long
#define ld long double
#define tii tuple<int,int,int>
#define tii4 tuple<int,int,int,int>
#define pii pair<int,int>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
const int maxn=2e5+5, M=1e6, INF=0x3f3f3f3f, MOD=998244353;
int v[maxn], poder[maxn], pai[maxn], mark[maxn], ans[maxn];
pii aux[maxn];
set<pii> adj[maxn];
int find(int x){
if(mark[x]) return pai[x];
mark[x]=true;
if(pai[x]==-1) return -1;
return pai[x]=find(pai[x]);
}
int solve(){
int n,m; cin >> n >> m;
for(int i=1; i<=n; i++){
cin >> v[i];
aux[i]={v[i],i};
poder[i]=v[i];
}
for(int i=1; i<=m; i++){
int a,b; cin >> a >> b;
adj[a].insert({v[b],b});
adj[b].insert({v[a],a});
}
sort(aux+1, aux+1+n);
for(int i=1; i<n; i++){
auto[val_cur, cur] = aux[i];
mark[cur]=true;
pii wow = *adj[cur].begin();
while(mark[wow.ss]){
adj[cur].erase(adj[cur].begin());
wow = *adj[cur].begin();
}
auto[val_viz,viz] = *adj[cur].begin();
if(v[viz]<=poder[cur]) pai[cur]=viz;
else pai[cur]=-1;
// cout << cur << " " << viz << " " << pai[cur] << endl;
poder[viz]+=poder[cur];
if(adj[viz].size()<adj[cur].size()) swap(adj[cur],adj[viz]);
for(pii x : adj[cur]) adj[viz].insert(x);
}
memset(mark,0,sizeof mark);
int last = aux[n].ss;
ans[last]=1;
pai[last]=last, mark[last]=true;
// for(int i=1; i<=n; i++) cout << pai[i] << " ";
// cout << endl;
for(int i=1; i<=n; i++)if(!mark[i]) find(i);
for(int i=1; i<=n; i++){
if(pai[i]==-1) cout << 0;
else cout << ans[pai[i]];
}
cout << '\n';
return 0;
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int t=1;
// cin >> t;
while(t--){
if(solve()) break;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
16984 KB |
Output is correct |
2 |
Correct |
4 ms |
16988 KB |
Output is correct |
3 |
Correct |
3 ms |
17056 KB |
Output is correct |
4 |
Correct |
5 ms |
17244 KB |
Output is correct |
5 |
Correct |
5 ms |
17360 KB |
Output is correct |
6 |
Correct |
4 ms |
17244 KB |
Output is correct |
7 |
Correct |
4 ms |
17364 KB |
Output is correct |
8 |
Correct |
4 ms |
17244 KB |
Output is correct |
9 |
Correct |
4 ms |
17244 KB |
Output is correct |
10 |
Correct |
4 ms |
17244 KB |
Output is correct |
11 |
Correct |
5 ms |
17240 KB |
Output is correct |
12 |
Correct |
5 ms |
17240 KB |
Output is correct |
13 |
Correct |
4 ms |
17244 KB |
Output is correct |
14 |
Correct |
4 ms |
17244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
16988 KB |
Output is correct |
2 |
Correct |
3 ms |
17036 KB |
Output is correct |
3 |
Correct |
165 ms |
50340 KB |
Output is correct |
4 |
Correct |
181 ms |
51284 KB |
Output is correct |
5 |
Correct |
212 ms |
49492 KB |
Output is correct |
6 |
Correct |
236 ms |
52048 KB |
Output is correct |
7 |
Correct |
241 ms |
52052 KB |
Output is correct |
8 |
Correct |
276 ms |
56492 KB |
Output is correct |
9 |
Correct |
206 ms |
53324 KB |
Output is correct |
10 |
Correct |
260 ms |
49492 KB |
Output is correct |
11 |
Correct |
221 ms |
51796 KB |
Output is correct |
12 |
Correct |
279 ms |
52124 KB |
Output is correct |
13 |
Correct |
162 ms |
51448 KB |
Output is correct |
14 |
Correct |
171 ms |
51376 KB |
Output is correct |
15 |
Correct |
149 ms |
50480 KB |
Output is correct |
16 |
Correct |
81 ms |
49232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
16988 KB |
Output is correct |
2 |
Correct |
329 ms |
55980 KB |
Output is correct |
3 |
Correct |
302 ms |
56012 KB |
Output is correct |
4 |
Correct |
169 ms |
52924 KB |
Output is correct |
5 |
Correct |
150 ms |
50516 KB |
Output is correct |
6 |
Correct |
312 ms |
56488 KB |
Output is correct |
7 |
Correct |
201 ms |
50496 KB |
Output is correct |
8 |
Correct |
217 ms |
50512 KB |
Output is correct |
9 |
Correct |
80 ms |
49276 KB |
Output is correct |
10 |
Correct |
211 ms |
63592 KB |
Output is correct |
11 |
Correct |
231 ms |
55080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
16988 KB |
Output is correct |
2 |
Correct |
353 ms |
54540 KB |
Output is correct |
3 |
Correct |
319 ms |
54096 KB |
Output is correct |
4 |
Correct |
359 ms |
54468 KB |
Output is correct |
5 |
Correct |
301 ms |
54304 KB |
Output is correct |
6 |
Correct |
294 ms |
54948 KB |
Output is correct |
7 |
Correct |
235 ms |
51796 KB |
Output is correct |
8 |
Correct |
125 ms |
56776 KB |
Output is correct |
9 |
Correct |
296 ms |
52052 KB |
Output is correct |
10 |
Correct |
283 ms |
52948 KB |
Output is correct |
11 |
Correct |
275 ms |
55300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
16984 KB |
Output is correct |
2 |
Correct |
4 ms |
16988 KB |
Output is correct |
3 |
Correct |
3 ms |
17056 KB |
Output is correct |
4 |
Correct |
5 ms |
17244 KB |
Output is correct |
5 |
Correct |
5 ms |
17360 KB |
Output is correct |
6 |
Correct |
4 ms |
17244 KB |
Output is correct |
7 |
Correct |
4 ms |
17364 KB |
Output is correct |
8 |
Correct |
4 ms |
17244 KB |
Output is correct |
9 |
Correct |
4 ms |
17244 KB |
Output is correct |
10 |
Correct |
4 ms |
17244 KB |
Output is correct |
11 |
Correct |
5 ms |
17240 KB |
Output is correct |
12 |
Correct |
5 ms |
17240 KB |
Output is correct |
13 |
Correct |
4 ms |
17244 KB |
Output is correct |
14 |
Correct |
4 ms |
17244 KB |
Output is correct |
15 |
Correct |
3 ms |
16988 KB |
Output is correct |
16 |
Correct |
3 ms |
17036 KB |
Output is correct |
17 |
Correct |
165 ms |
50340 KB |
Output is correct |
18 |
Correct |
181 ms |
51284 KB |
Output is correct |
19 |
Correct |
212 ms |
49492 KB |
Output is correct |
20 |
Correct |
236 ms |
52048 KB |
Output is correct |
21 |
Correct |
241 ms |
52052 KB |
Output is correct |
22 |
Correct |
276 ms |
56492 KB |
Output is correct |
23 |
Correct |
206 ms |
53324 KB |
Output is correct |
24 |
Correct |
260 ms |
49492 KB |
Output is correct |
25 |
Correct |
221 ms |
51796 KB |
Output is correct |
26 |
Correct |
279 ms |
52124 KB |
Output is correct |
27 |
Correct |
162 ms |
51448 KB |
Output is correct |
28 |
Correct |
171 ms |
51376 KB |
Output is correct |
29 |
Correct |
149 ms |
50480 KB |
Output is correct |
30 |
Correct |
81 ms |
49232 KB |
Output is correct |
31 |
Correct |
3 ms |
16988 KB |
Output is correct |
32 |
Correct |
329 ms |
55980 KB |
Output is correct |
33 |
Correct |
302 ms |
56012 KB |
Output is correct |
34 |
Correct |
169 ms |
52924 KB |
Output is correct |
35 |
Correct |
150 ms |
50516 KB |
Output is correct |
36 |
Correct |
312 ms |
56488 KB |
Output is correct |
37 |
Correct |
201 ms |
50496 KB |
Output is correct |
38 |
Correct |
217 ms |
50512 KB |
Output is correct |
39 |
Correct |
80 ms |
49276 KB |
Output is correct |
40 |
Correct |
211 ms |
63592 KB |
Output is correct |
41 |
Correct |
231 ms |
55080 KB |
Output is correct |
42 |
Correct |
3 ms |
16988 KB |
Output is correct |
43 |
Correct |
353 ms |
54540 KB |
Output is correct |
44 |
Correct |
319 ms |
54096 KB |
Output is correct |
45 |
Correct |
359 ms |
54468 KB |
Output is correct |
46 |
Correct |
301 ms |
54304 KB |
Output is correct |
47 |
Correct |
294 ms |
54948 KB |
Output is correct |
48 |
Correct |
235 ms |
51796 KB |
Output is correct |
49 |
Correct |
125 ms |
56776 KB |
Output is correct |
50 |
Correct |
296 ms |
52052 KB |
Output is correct |
51 |
Correct |
283 ms |
52948 KB |
Output is correct |
52 |
Correct |
275 ms |
55300 KB |
Output is correct |
53 |
Correct |
3 ms |
16988 KB |
Output is correct |
54 |
Correct |
3 ms |
16984 KB |
Output is correct |
55 |
Correct |
3 ms |
16988 KB |
Output is correct |
56 |
Correct |
4 ms |
17308 KB |
Output is correct |
57 |
Correct |
5 ms |
17248 KB |
Output is correct |
58 |
Correct |
4 ms |
17244 KB |
Output is correct |
59 |
Correct |
4 ms |
17244 KB |
Output is correct |
60 |
Correct |
4 ms |
17244 KB |
Output is correct |
61 |
Correct |
4 ms |
17244 KB |
Output is correct |
62 |
Correct |
4 ms |
17412 KB |
Output is correct |
63 |
Correct |
4 ms |
17264 KB |
Output is correct |
64 |
Correct |
4 ms |
17244 KB |
Output is correct |
65 |
Correct |
4 ms |
17304 KB |
Output is correct |
66 |
Correct |
4 ms |
17496 KB |
Output is correct |
67 |
Correct |
181 ms |
50260 KB |
Output is correct |
68 |
Correct |
175 ms |
51284 KB |
Output is correct |
69 |
Correct |
246 ms |
49392 KB |
Output is correct |
70 |
Correct |
223 ms |
51976 KB |
Output is correct |
71 |
Correct |
224 ms |
52056 KB |
Output is correct |
72 |
Correct |
287 ms |
56572 KB |
Output is correct |
73 |
Correct |
194 ms |
53336 KB |
Output is correct |
74 |
Correct |
257 ms |
49548 KB |
Output is correct |
75 |
Correct |
215 ms |
51792 KB |
Output is correct |
76 |
Correct |
269 ms |
52068 KB |
Output is correct |
77 |
Correct |
184 ms |
51308 KB |
Output is correct |
78 |
Correct |
170 ms |
51280 KB |
Output is correct |
79 |
Correct |
153 ms |
50328 KB |
Output is correct |
80 |
Correct |
85 ms |
49428 KB |
Output is correct |
81 |
Correct |
309 ms |
55952 KB |
Output is correct |
82 |
Correct |
310 ms |
56148 KB |
Output is correct |
83 |
Correct |
175 ms |
53000 KB |
Output is correct |
84 |
Correct |
153 ms |
50560 KB |
Output is correct |
85 |
Correct |
310 ms |
56056 KB |
Output is correct |
86 |
Correct |
220 ms |
50300 KB |
Output is correct |
87 |
Correct |
253 ms |
50264 KB |
Output is correct |
88 |
Correct |
202 ms |
63824 KB |
Output is correct |
89 |
Correct |
232 ms |
55172 KB |
Output is correct |
90 |
Correct |
346 ms |
54608 KB |
Output is correct |
91 |
Correct |
366 ms |
54196 KB |
Output is correct |
92 |
Correct |
336 ms |
54268 KB |
Output is correct |
93 |
Correct |
309 ms |
54264 KB |
Output is correct |
94 |
Correct |
307 ms |
54868 KB |
Output is correct |
95 |
Correct |
252 ms |
51604 KB |
Output is correct |
96 |
Correct |
123 ms |
56408 KB |
Output is correct |
97 |
Correct |
315 ms |
51796 KB |
Output is correct |
98 |
Correct |
307 ms |
52848 KB |
Output is correct |
99 |
Correct |
244 ms |
55080 KB |
Output is correct |
100 |
Correct |
286 ms |
44732 KB |
Output is correct |
101 |
Correct |
350 ms |
54352 KB |
Output is correct |
102 |
Correct |
377 ms |
60680 KB |
Output is correct |
103 |
Correct |
375 ms |
58080 KB |
Output is correct |
104 |
Correct |
353 ms |
54748 KB |
Output is correct |