/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
const int N = 2e5 + 100;
int a[N], pos[N];
struct Dsu{
vector<int> s, p, mx;
vector<long long> sum;
Dsu(int n){
s.resize(n + 1, 1);
p.resize(n + 1);
mx.resize(n + 1);
sum.resize(n + 1, 0ll);
for(int i = 0; i <= n; ++i) p[i] = mx[i] = i;
for(int i = 0; i <= n; ++i) sum[i] = a[i];
}
int find(int v){
if(v==p[v]) return v;
return (p[v]=find(p[v]));
}
void merge(int c, int b){
c = find(c);
b = find(b);
if(c != b){
if(s[c] > s[b]) swap(c, b);
p[c] = b;
s[b] += s[c];
sum[b] += sum[c];
mx[b] = pos[mx[c]] > pos[mx[b]] ? mx[c] : mx[b];
}
}
};
int n, m;
vector<int> g[N];
vector<bool> vis;
vector<int> ans;
pair<int, int> b[N];
int main(){
cin.tie(0); ios::sync_with_stdio(0);
cin >> n >> m;
for(int i = 1; i <= n; ++i) cin >> a[i];
for(int i = 1; i <= n; ++i) b[i] = {a[i], i};
for(int i = 0; i < m; ++i){
int a, b; cin >> a >> b;
g[a].pb(b);
g[b].pb(a);
}
Dsu d(n), M(n);
sort(b + 1, b + 1 + n);
ans.resize(n + 1, 0);
vis.resize(n + 1, 0);
for(int i = 1; i <= n; ++i) pos[b[i].second] = i;
for(int i = 1; i <= n; ++i){
int v = b[i].second;
for(int u: g[v]){
if(vis[u]){
int co = d.find(u);
if(d.sum[co] >= a[v]){
M.merge(v, d.mx[co]);
}else{
ans[u] = -1;
}
}
}
for(int u: g[v]){
if(vis[u]){
d.merge(u, v);
}
}
vis[v] = 1;
}
vis.clear();
vis.resize(n+1, 0);
int co = M.find(b[n].second);
for(int i = 1; i <= n; ++i) if(ans[i] != -1) ans[i] = (M.find(i) == co ? 1 : 0);
for(int i = 1; i <= n; ++i) cout << (ans[i]==-1?0:ans[i]);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5204 KB |
Output is correct |
6 |
Correct |
4 ms |
5204 KB |
Output is correct |
7 |
Correct |
4 ms |
5172 KB |
Output is correct |
8 |
Correct |
4 ms |
5104 KB |
Output is correct |
9 |
Correct |
4 ms |
5168 KB |
Output is correct |
10 |
Correct |
4 ms |
5204 KB |
Output is correct |
11 |
Correct |
4 ms |
5172 KB |
Output is correct |
12 |
Correct |
4 ms |
5172 KB |
Output is correct |
13 |
Correct |
4 ms |
5136 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
141 ms |
23264 KB |
Output is correct |
4 |
Correct |
139 ms |
23176 KB |
Output is correct |
5 |
Correct |
151 ms |
22652 KB |
Output is correct |
6 |
Correct |
187 ms |
23212 KB |
Output is correct |
7 |
Correct |
150 ms |
23244 KB |
Output is correct |
8 |
Correct |
149 ms |
23244 KB |
Output is correct |
9 |
Correct |
121 ms |
23192 KB |
Output is correct |
10 |
Correct |
124 ms |
23980 KB |
Output is correct |
11 |
Correct |
136 ms |
23924 KB |
Output is correct |
12 |
Correct |
148 ms |
23244 KB |
Output is correct |
13 |
Correct |
129 ms |
23256 KB |
Output is correct |
14 |
Correct |
128 ms |
23276 KB |
Output is correct |
15 |
Correct |
133 ms |
23328 KB |
Output is correct |
16 |
Correct |
96 ms |
23016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
195 ms |
23224 KB |
Output is correct |
3 |
Correct |
193 ms |
27652 KB |
Output is correct |
4 |
Correct |
160 ms |
27692 KB |
Output is correct |
5 |
Correct |
125 ms |
26108 KB |
Output is correct |
6 |
Correct |
201 ms |
27664 KB |
Output is correct |
7 |
Correct |
151 ms |
27724 KB |
Output is correct |
8 |
Correct |
151 ms |
27872 KB |
Output is correct |
9 |
Correct |
102 ms |
26852 KB |
Output is correct |
10 |
Correct |
125 ms |
26960 KB |
Output is correct |
11 |
Correct |
150 ms |
26120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
202 ms |
23156 KB |
Output is correct |
3 |
Correct |
217 ms |
27552 KB |
Output is correct |
4 |
Correct |
206 ms |
27724 KB |
Output is correct |
5 |
Correct |
189 ms |
27656 KB |
Output is correct |
6 |
Correct |
160 ms |
26672 KB |
Output is correct |
7 |
Correct |
140 ms |
28368 KB |
Output is correct |
8 |
Correct |
89 ms |
26540 KB |
Output is correct |
9 |
Correct |
107 ms |
17740 KB |
Output is correct |
10 |
Correct |
158 ms |
26296 KB |
Output is correct |
11 |
Correct |
153 ms |
26128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5204 KB |
Output is correct |
6 |
Correct |
4 ms |
5204 KB |
Output is correct |
7 |
Correct |
4 ms |
5172 KB |
Output is correct |
8 |
Correct |
4 ms |
5104 KB |
Output is correct |
9 |
Correct |
4 ms |
5168 KB |
Output is correct |
10 |
Correct |
4 ms |
5204 KB |
Output is correct |
11 |
Correct |
4 ms |
5172 KB |
Output is correct |
12 |
Correct |
4 ms |
5172 KB |
Output is correct |
13 |
Correct |
4 ms |
5136 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
141 ms |
23264 KB |
Output is correct |
18 |
Correct |
139 ms |
23176 KB |
Output is correct |
19 |
Correct |
151 ms |
22652 KB |
Output is correct |
20 |
Correct |
187 ms |
23212 KB |
Output is correct |
21 |
Correct |
150 ms |
23244 KB |
Output is correct |
22 |
Correct |
149 ms |
23244 KB |
Output is correct |
23 |
Correct |
121 ms |
23192 KB |
Output is correct |
24 |
Correct |
124 ms |
23980 KB |
Output is correct |
25 |
Correct |
136 ms |
23924 KB |
Output is correct |
26 |
Correct |
148 ms |
23244 KB |
Output is correct |
27 |
Correct |
129 ms |
23256 KB |
Output is correct |
28 |
Correct |
128 ms |
23276 KB |
Output is correct |
29 |
Correct |
133 ms |
23328 KB |
Output is correct |
30 |
Correct |
96 ms |
23016 KB |
Output is correct |
31 |
Correct |
2 ms |
4948 KB |
Output is correct |
32 |
Correct |
195 ms |
23224 KB |
Output is correct |
33 |
Correct |
193 ms |
27652 KB |
Output is correct |
34 |
Correct |
160 ms |
27692 KB |
Output is correct |
35 |
Correct |
125 ms |
26108 KB |
Output is correct |
36 |
Correct |
201 ms |
27664 KB |
Output is correct |
37 |
Correct |
151 ms |
27724 KB |
Output is correct |
38 |
Correct |
151 ms |
27872 KB |
Output is correct |
39 |
Correct |
102 ms |
26852 KB |
Output is correct |
40 |
Correct |
125 ms |
26960 KB |
Output is correct |
41 |
Correct |
150 ms |
26120 KB |
Output is correct |
42 |
Correct |
2 ms |
4948 KB |
Output is correct |
43 |
Correct |
202 ms |
23156 KB |
Output is correct |
44 |
Correct |
217 ms |
27552 KB |
Output is correct |
45 |
Correct |
206 ms |
27724 KB |
Output is correct |
46 |
Correct |
189 ms |
27656 KB |
Output is correct |
47 |
Correct |
160 ms |
26672 KB |
Output is correct |
48 |
Correct |
140 ms |
28368 KB |
Output is correct |
49 |
Correct |
89 ms |
26540 KB |
Output is correct |
50 |
Correct |
107 ms |
17740 KB |
Output is correct |
51 |
Correct |
158 ms |
26296 KB |
Output is correct |
52 |
Correct |
153 ms |
26128 KB |
Output is correct |
53 |
Correct |
3 ms |
4948 KB |
Output is correct |
54 |
Correct |
2 ms |
4948 KB |
Output is correct |
55 |
Correct |
3 ms |
4948 KB |
Output is correct |
56 |
Correct |
4 ms |
5196 KB |
Output is correct |
57 |
Correct |
4 ms |
5204 KB |
Output is correct |
58 |
Correct |
4 ms |
5204 KB |
Output is correct |
59 |
Correct |
5 ms |
5204 KB |
Output is correct |
60 |
Correct |
4 ms |
5176 KB |
Output is correct |
61 |
Correct |
4 ms |
5216 KB |
Output is correct |
62 |
Correct |
5 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 |
3 ms |
5204 KB |
Output is correct |
66 |
Correct |
4 ms |
5228 KB |
Output is correct |
67 |
Correct |
161 ms |
27680 KB |
Output is correct |
68 |
Correct |
125 ms |
26248 KB |
Output is correct |
69 |
Correct |
177 ms |
26936 KB |
Output is correct |
70 |
Correct |
154 ms |
27516 KB |
Output is correct |
71 |
Correct |
158 ms |
27608 KB |
Output is correct |
72 |
Correct |
154 ms |
27700 KB |
Output is correct |
73 |
Correct |
141 ms |
27600 KB |
Output is correct |
74 |
Correct |
106 ms |
27536 KB |
Output is correct |
75 |
Correct |
130 ms |
27392 KB |
Output is correct |
76 |
Correct |
167 ms |
26316 KB |
Output is correct |
77 |
Correct |
126 ms |
26188 KB |
Output is correct |
78 |
Correct |
126 ms |
26316 KB |
Output is correct |
79 |
Correct |
131 ms |
27676 KB |
Output is correct |
80 |
Correct |
93 ms |
26784 KB |
Output is correct |
81 |
Correct |
184 ms |
27492 KB |
Output is correct |
82 |
Correct |
199 ms |
27764 KB |
Output is correct |
83 |
Correct |
149 ms |
27748 KB |
Output is correct |
84 |
Correct |
132 ms |
26188 KB |
Output is correct |
85 |
Correct |
181 ms |
27724 KB |
Output is correct |
86 |
Correct |
160 ms |
27768 KB |
Output is correct |
87 |
Correct |
163 ms |
27648 KB |
Output is correct |
88 |
Correct |
151 ms |
27044 KB |
Output is correct |
89 |
Correct |
149 ms |
26172 KB |
Output is correct |
90 |
Correct |
200 ms |
27676 KB |
Output is correct |
91 |
Correct |
193 ms |
27572 KB |
Output is correct |
92 |
Correct |
234 ms |
27724 KB |
Output is correct |
93 |
Correct |
178 ms |
27652 KB |
Output is correct |
94 |
Correct |
169 ms |
26660 KB |
Output is correct |
95 |
Correct |
133 ms |
28360 KB |
Output is correct |
96 |
Correct |
88 ms |
26472 KB |
Output is correct |
97 |
Correct |
107 ms |
17732 KB |
Output is correct |
98 |
Correct |
159 ms |
26140 KB |
Output is correct |
99 |
Correct |
143 ms |
26188 KB |
Output is correct |
100 |
Correct |
57 ms |
9436 KB |
Output is correct |
101 |
Correct |
218 ms |
27684 KB |
Output is correct |
102 |
Correct |
165 ms |
23372 KB |
Output is correct |
103 |
Correct |
180 ms |
24388 KB |
Output is correct |
104 |
Correct |
202 ms |
27496 KB |
Output is correct |