//https://oj.uz/submission/694082
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pli = pair<ll, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define F first
#define S second
#define PB push_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
const int MXN = 2e5+5;
int n, m;
ll A[MXN];
vi adj[MXN];
vi res_adj[MXN]; // directional graph describes how I propagate results
struct DSU {
int n;
vi par;
vi sz;
vi mx_id;
vl pop;
void init(int _n) {
n = _n;
par = vi(n+1);
sz = vi(n+1, 1);
mx_id = vi(n+1);
pop = vl(n+1);
iota(par.begin()+1, par.begin()+n+1, 1);
iota(mx_id.begin()+1, mx_id.begin()+n+1, 1);
for(int i = 1; i <= n; i++) pop[i] = A[i];
}
int find_set(int u) { return par[u] == u ? u : par[u] = find_set(par[u]); }
void unite(int u, int v) {
u = find_set(u), v = find_set(v);
if(u == v) return;
int new_mx_id = A[mx_id[u]] >= A[mx_id[v]] ? mx_id[u] : mx_id[v];
if(sz[u] < sz[v]) swap(u, v);
mx_id[u] = new_mx_id;
par[v] = u;
sz[u] += sz[v];
pop[u] += pop[v];
}
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> A[i];
for(int i = 0; i < m; i++) {
int u, v; cin >> u >> v;
adj[u].PB(v), adj[v].PB(u);
}
string ans(n+1, '0');
ll mx = *max_element(A+1, A+n+1);
vector<pli> B;
for(int i = 1; i <= n; i++) {
if(A[i] == mx) ans[i] = '1';
B.PB({A[i], i});
}
sort(all(B));
DSU dsu;
dsu.init(n);
for(auto p : B) {
int u = p.S;
for(int v : adj[u]) {
if(A[v] <= A[u]) {
if(dsu.pop[dsu.find_set(v)] >= A[u]) {
res_adj[u].PB(dsu.mx_id[dsu.find_set(v)]);
}
}
}
for(int v : adj[u]) {
if(A[v] <= A[u]) {
dsu.unite(u, v);
}
}
}
queue<int> Q;
for(int i = 1; i <= n; i++) if(ans[i] == '1') Q.push(i);
while(!Q.empty()) {
int i = Q.front();
Q.pop();
for(int j : res_adj[i]) {
if(ans[j] == '0') {
ans[j] = '1';
Q.push(j);
}
}
}
cout << ans.substr(1) << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
8 ms |
9708 KB |
Output is correct |
4 |
Correct |
10 ms |
9776 KB |
Output is correct |
5 |
Correct |
8 ms |
9812 KB |
Output is correct |
6 |
Correct |
7 ms |
9812 KB |
Output is correct |
7 |
Correct |
9 ms |
9812 KB |
Output is correct |
8 |
Correct |
9 ms |
9812 KB |
Output is correct |
9 |
Correct |
6 ms |
9940 KB |
Output is correct |
10 |
Correct |
10 ms |
9808 KB |
Output is correct |
11 |
Correct |
6 ms |
9856 KB |
Output is correct |
12 |
Correct |
8 ms |
9812 KB |
Output is correct |
13 |
Correct |
6 ms |
9940 KB |
Output is correct |
14 |
Correct |
9 ms |
9812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
136 ms |
28616 KB |
Output is correct |
4 |
Correct |
146 ms |
31460 KB |
Output is correct |
5 |
Correct |
143 ms |
27316 KB |
Output is correct |
6 |
Correct |
204 ms |
27896 KB |
Output is correct |
7 |
Correct |
185 ms |
27992 KB |
Output is correct |
8 |
Correct |
226 ms |
31496 KB |
Output is correct |
9 |
Correct |
151 ms |
26552 KB |
Output is correct |
10 |
Correct |
104 ms |
25868 KB |
Output is correct |
11 |
Correct |
155 ms |
33572 KB |
Output is correct |
12 |
Correct |
195 ms |
31432 KB |
Output is correct |
13 |
Correct |
142 ms |
31440 KB |
Output is correct |
14 |
Correct |
158 ms |
31500 KB |
Output is correct |
15 |
Correct |
152 ms |
31380 KB |
Output is correct |
16 |
Correct |
97 ms |
31164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9628 KB |
Output is correct |
2 |
Correct |
204 ms |
27512 KB |
Output is correct |
3 |
Correct |
207 ms |
27648 KB |
Output is correct |
4 |
Correct |
200 ms |
31956 KB |
Output is correct |
5 |
Correct |
148 ms |
31440 KB |
Output is correct |
6 |
Correct |
214 ms |
27632 KB |
Output is correct |
7 |
Correct |
182 ms |
31376 KB |
Output is correct |
8 |
Correct |
194 ms |
31392 KB |
Output is correct |
9 |
Correct |
101 ms |
31148 KB |
Output is correct |
10 |
Correct |
166 ms |
28296 KB |
Output is correct |
11 |
Correct |
183 ms |
29100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9684 KB |
Output is correct |
2 |
Correct |
206 ms |
28388 KB |
Output is correct |
3 |
Correct |
299 ms |
28360 KB |
Output is correct |
4 |
Correct |
225 ms |
28688 KB |
Output is correct |
5 |
Correct |
216 ms |
32036 KB |
Output is correct |
6 |
Correct |
248 ms |
30988 KB |
Output is correct |
7 |
Correct |
147 ms |
33168 KB |
Output is correct |
8 |
Correct |
104 ms |
31512 KB |
Output is correct |
9 |
Correct |
147 ms |
21452 KB |
Output is correct |
10 |
Correct |
181 ms |
31564 KB |
Output is correct |
11 |
Correct |
167 ms |
29092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
8 ms |
9708 KB |
Output is correct |
4 |
Correct |
10 ms |
9776 KB |
Output is correct |
5 |
Correct |
8 ms |
9812 KB |
Output is correct |
6 |
Correct |
7 ms |
9812 KB |
Output is correct |
7 |
Correct |
9 ms |
9812 KB |
Output is correct |
8 |
Correct |
9 ms |
9812 KB |
Output is correct |
9 |
Correct |
6 ms |
9940 KB |
Output is correct |
10 |
Correct |
10 ms |
9808 KB |
Output is correct |
11 |
Correct |
6 ms |
9856 KB |
Output is correct |
12 |
Correct |
8 ms |
9812 KB |
Output is correct |
13 |
Correct |
6 ms |
9940 KB |
Output is correct |
14 |
Correct |
9 ms |
9812 KB |
Output is correct |
15 |
Correct |
8 ms |
9684 KB |
Output is correct |
16 |
Correct |
7 ms |
9684 KB |
Output is correct |
17 |
Correct |
136 ms |
28616 KB |
Output is correct |
18 |
Correct |
146 ms |
31460 KB |
Output is correct |
19 |
Correct |
143 ms |
27316 KB |
Output is correct |
20 |
Correct |
204 ms |
27896 KB |
Output is correct |
21 |
Correct |
185 ms |
27992 KB |
Output is correct |
22 |
Correct |
226 ms |
31496 KB |
Output is correct |
23 |
Correct |
151 ms |
26552 KB |
Output is correct |
24 |
Correct |
104 ms |
25868 KB |
Output is correct |
25 |
Correct |
155 ms |
33572 KB |
Output is correct |
26 |
Correct |
195 ms |
31432 KB |
Output is correct |
27 |
Correct |
142 ms |
31440 KB |
Output is correct |
28 |
Correct |
158 ms |
31500 KB |
Output is correct |
29 |
Correct |
152 ms |
31380 KB |
Output is correct |
30 |
Correct |
97 ms |
31164 KB |
Output is correct |
31 |
Correct |
6 ms |
9628 KB |
Output is correct |
32 |
Correct |
204 ms |
27512 KB |
Output is correct |
33 |
Correct |
207 ms |
27648 KB |
Output is correct |
34 |
Correct |
200 ms |
31956 KB |
Output is correct |
35 |
Correct |
148 ms |
31440 KB |
Output is correct |
36 |
Correct |
214 ms |
27632 KB |
Output is correct |
37 |
Correct |
182 ms |
31376 KB |
Output is correct |
38 |
Correct |
194 ms |
31392 KB |
Output is correct |
39 |
Correct |
101 ms |
31148 KB |
Output is correct |
40 |
Correct |
166 ms |
28296 KB |
Output is correct |
41 |
Correct |
183 ms |
29100 KB |
Output is correct |
42 |
Correct |
9 ms |
9684 KB |
Output is correct |
43 |
Correct |
206 ms |
28388 KB |
Output is correct |
44 |
Correct |
299 ms |
28360 KB |
Output is correct |
45 |
Correct |
225 ms |
28688 KB |
Output is correct |
46 |
Correct |
216 ms |
32036 KB |
Output is correct |
47 |
Correct |
248 ms |
30988 KB |
Output is correct |
48 |
Correct |
147 ms |
33168 KB |
Output is correct |
49 |
Correct |
104 ms |
31512 KB |
Output is correct |
50 |
Correct |
147 ms |
21452 KB |
Output is correct |
51 |
Correct |
181 ms |
31564 KB |
Output is correct |
52 |
Correct |
167 ms |
29092 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
8 ms |
9692 KB |
Output is correct |
55 |
Correct |
8 ms |
9684 KB |
Output is correct |
56 |
Correct |
8 ms |
9812 KB |
Output is correct |
57 |
Correct |
9 ms |
9872 KB |
Output is correct |
58 |
Correct |
8 ms |
9808 KB |
Output is correct |
59 |
Correct |
9 ms |
9784 KB |
Output is correct |
60 |
Correct |
8 ms |
9768 KB |
Output is correct |
61 |
Correct |
7 ms |
9928 KB |
Output is correct |
62 |
Correct |
10 ms |
9812 KB |
Output is correct |
63 |
Correct |
9 ms |
9812 KB |
Output is correct |
64 |
Correct |
7 ms |
9812 KB |
Output is correct |
65 |
Correct |
6 ms |
9940 KB |
Output is correct |
66 |
Correct |
6 ms |
9812 KB |
Output is correct |
67 |
Correct |
165 ms |
28616 KB |
Output is correct |
68 |
Correct |
162 ms |
31552 KB |
Output is correct |
69 |
Correct |
159 ms |
27384 KB |
Output is correct |
70 |
Correct |
163 ms |
27968 KB |
Output is correct |
71 |
Correct |
235 ms |
27948 KB |
Output is correct |
72 |
Correct |
207 ms |
31476 KB |
Output is correct |
73 |
Correct |
170 ms |
26584 KB |
Output is correct |
74 |
Correct |
132 ms |
25880 KB |
Output is correct |
75 |
Correct |
158 ms |
33604 KB |
Output is correct |
76 |
Correct |
159 ms |
31292 KB |
Output is correct |
77 |
Correct |
189 ms |
31432 KB |
Output is correct |
78 |
Correct |
150 ms |
31512 KB |
Output is correct |
79 |
Correct |
160 ms |
31420 KB |
Output is correct |
80 |
Correct |
126 ms |
31132 KB |
Output is correct |
81 |
Correct |
198 ms |
27532 KB |
Output is correct |
82 |
Correct |
212 ms |
27648 KB |
Output is correct |
83 |
Correct |
232 ms |
31956 KB |
Output is correct |
84 |
Correct |
155 ms |
31336 KB |
Output is correct |
85 |
Correct |
179 ms |
27600 KB |
Output is correct |
86 |
Correct |
160 ms |
31376 KB |
Output is correct |
87 |
Correct |
177 ms |
31420 KB |
Output is correct |
88 |
Correct |
146 ms |
28292 KB |
Output is correct |
89 |
Correct |
145 ms |
29104 KB |
Output is correct |
90 |
Correct |
199 ms |
28364 KB |
Output is correct |
91 |
Correct |
255 ms |
28440 KB |
Output is correct |
92 |
Correct |
253 ms |
28668 KB |
Output is correct |
93 |
Correct |
217 ms |
32052 KB |
Output is correct |
94 |
Correct |
194 ms |
31120 KB |
Output is correct |
95 |
Correct |
139 ms |
33220 KB |
Output is correct |
96 |
Correct |
96 ms |
31408 KB |
Output is correct |
97 |
Correct |
129 ms |
21432 KB |
Output is correct |
98 |
Correct |
203 ms |
31552 KB |
Output is correct |
99 |
Correct |
155 ms |
29096 KB |
Output is correct |
100 |
Correct |
55 ms |
13088 KB |
Output is correct |
101 |
Correct |
230 ms |
27812 KB |
Output is correct |
102 |
Correct |
191 ms |
27396 KB |
Output is correct |
103 |
Correct |
206 ms |
25268 KB |
Output is correct |
104 |
Correct |
241 ms |
27500 KB |
Output is correct |