#include <bits/stdc++.h>
using namespace std;
#ifdef DLOCAL
#define dout cout
#else
#define dout cerr
#endif
using ll = long long;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, M; cin >> N >> M;
vector<int> A(N); for(auto& x : A) cin >> x;
vector<vector<int>> adj(N);
for(int i = 0; i < M; i++) {
int u, v; cin >> u >> v; --u, --v;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector<int> ord(N); iota(begin(ord), end(ord), 0);
sort(begin(ord), end(ord), [&](int x, int y) {
return A[x] < A[y];
});
string ans(N, '1');
vector<ll> X(N);
vector<int> ID(N);
vector<vector<int>> P(N), R(N);
for(int i = 0; i < N; i++) {
X[i] = A[i];
ID[i] = i;
P[i] = R[i] = {i};
}
auto merge = [&](int u, int v) {
u = ID[u], v = ID[v];
if (u == v) return;
if (size(P[u]) > size(P[v])) swap(u, v);
for(auto x : P[u]) {
P[v].push_back(x);
X[v] += A[x];
ID[x] = v;
}
for(auto x : R[u]) R[v].push_back(x);
};
for(auto u : ord) {
for(auto v : adj[u]) {
if (A[v] > A[u]) continue;
int V = ID[v];
if (X[V] < A[u]) {
for(auto x : R[V]) ans[x] = '0';
R[V] = {};
}
merge(v, u);
}
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
716 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
156 ms |
39680 KB |
Output is correct |
4 |
Correct |
174 ms |
48412 KB |
Output is correct |
5 |
Correct |
242 ms |
48036 KB |
Output is correct |
6 |
Correct |
272 ms |
49832 KB |
Output is correct |
7 |
Correct |
240 ms |
50440 KB |
Output is correct |
8 |
Correct |
232 ms |
46900 KB |
Output is correct |
9 |
Correct |
194 ms |
53988 KB |
Output is correct |
10 |
Correct |
174 ms |
43192 KB |
Output is correct |
11 |
Correct |
150 ms |
43812 KB |
Output is correct |
12 |
Correct |
273 ms |
45296 KB |
Output is correct |
13 |
Correct |
156 ms |
49488 KB |
Output is correct |
14 |
Correct |
165 ms |
48552 KB |
Output is correct |
15 |
Correct |
153 ms |
43704 KB |
Output is correct |
16 |
Correct |
97 ms |
42480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
294 ms |
47900 KB |
Output is correct |
3 |
Correct |
285 ms |
52412 KB |
Output is correct |
4 |
Correct |
179 ms |
51080 KB |
Output is correct |
5 |
Correct |
183 ms |
49272 KB |
Output is correct |
6 |
Correct |
278 ms |
52428 KB |
Output is correct |
7 |
Correct |
164 ms |
43672 KB |
Output is correct |
8 |
Correct |
181 ms |
43708 KB |
Output is correct |
9 |
Correct |
113 ms |
42464 KB |
Output is correct |
10 |
Correct |
160 ms |
47552 KB |
Output is correct |
11 |
Correct |
199 ms |
48724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
271 ms |
41612 KB |
Output is correct |
3 |
Correct |
257 ms |
47400 KB |
Output is correct |
4 |
Correct |
274 ms |
48848 KB |
Output is correct |
5 |
Correct |
240 ms |
49076 KB |
Output is correct |
6 |
Correct |
223 ms |
44468 KB |
Output is correct |
7 |
Correct |
131 ms |
44864 KB |
Output is correct |
8 |
Correct |
107 ms |
45552 KB |
Output is correct |
9 |
Correct |
122 ms |
24096 KB |
Output is correct |
10 |
Correct |
271 ms |
48652 KB |
Output is correct |
11 |
Correct |
189 ms |
49088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
716 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
156 ms |
39680 KB |
Output is correct |
18 |
Correct |
174 ms |
48412 KB |
Output is correct |
19 |
Correct |
242 ms |
48036 KB |
Output is correct |
20 |
Correct |
272 ms |
49832 KB |
Output is correct |
21 |
Correct |
240 ms |
50440 KB |
Output is correct |
22 |
Correct |
232 ms |
46900 KB |
Output is correct |
23 |
Correct |
194 ms |
53988 KB |
Output is correct |
24 |
Correct |
174 ms |
43192 KB |
Output is correct |
25 |
Correct |
150 ms |
43812 KB |
Output is correct |
26 |
Correct |
273 ms |
45296 KB |
Output is correct |
27 |
Correct |
156 ms |
49488 KB |
Output is correct |
28 |
Correct |
165 ms |
48552 KB |
Output is correct |
29 |
Correct |
153 ms |
43704 KB |
Output is correct |
30 |
Correct |
97 ms |
42480 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
294 ms |
47900 KB |
Output is correct |
33 |
Correct |
285 ms |
52412 KB |
Output is correct |
34 |
Correct |
179 ms |
51080 KB |
Output is correct |
35 |
Correct |
183 ms |
49272 KB |
Output is correct |
36 |
Correct |
278 ms |
52428 KB |
Output is correct |
37 |
Correct |
164 ms |
43672 KB |
Output is correct |
38 |
Correct |
181 ms |
43708 KB |
Output is correct |
39 |
Correct |
113 ms |
42464 KB |
Output is correct |
40 |
Correct |
160 ms |
47552 KB |
Output is correct |
41 |
Correct |
199 ms |
48724 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
271 ms |
41612 KB |
Output is correct |
44 |
Correct |
257 ms |
47400 KB |
Output is correct |
45 |
Correct |
274 ms |
48848 KB |
Output is correct |
46 |
Correct |
240 ms |
49076 KB |
Output is correct |
47 |
Correct |
223 ms |
44468 KB |
Output is correct |
48 |
Correct |
131 ms |
44864 KB |
Output is correct |
49 |
Correct |
107 ms |
45552 KB |
Output is correct |
50 |
Correct |
122 ms |
24096 KB |
Output is correct |
51 |
Correct |
271 ms |
48652 KB |
Output is correct |
52 |
Correct |
189 ms |
49088 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
324 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Correct |
2 ms |
596 KB |
Output is correct |
57 |
Correct |
2 ms |
724 KB |
Output is correct |
58 |
Correct |
2 ms |
596 KB |
Output is correct |
59 |
Correct |
2 ms |
596 KB |
Output is correct |
60 |
Correct |
2 ms |
596 KB |
Output is correct |
61 |
Correct |
2 ms |
740 KB |
Output is correct |
62 |
Correct |
2 ms |
724 KB |
Output is correct |
63 |
Correct |
2 ms |
716 KB |
Output is correct |
64 |
Correct |
1 ms |
724 KB |
Output is correct |
65 |
Correct |
2 ms |
716 KB |
Output is correct |
66 |
Correct |
2 ms |
724 KB |
Output is correct |
67 |
Correct |
164 ms |
44084 KB |
Output is correct |
68 |
Correct |
163 ms |
48636 KB |
Output is correct |
69 |
Correct |
209 ms |
48012 KB |
Output is correct |
70 |
Correct |
251 ms |
49820 KB |
Output is correct |
71 |
Correct |
215 ms |
50252 KB |
Output is correct |
72 |
Correct |
246 ms |
46900 KB |
Output is correct |
73 |
Correct |
178 ms |
53860 KB |
Output is correct |
74 |
Correct |
189 ms |
43188 KB |
Output is correct |
75 |
Correct |
149 ms |
43852 KB |
Output is correct |
76 |
Correct |
246 ms |
45344 KB |
Output is correct |
77 |
Correct |
158 ms |
49492 KB |
Output is correct |
78 |
Correct |
162 ms |
48496 KB |
Output is correct |
79 |
Correct |
166 ms |
43644 KB |
Output is correct |
80 |
Correct |
93 ms |
42460 KB |
Output is correct |
81 |
Correct |
268 ms |
52412 KB |
Output is correct |
82 |
Correct |
272 ms |
52492 KB |
Output is correct |
83 |
Correct |
156 ms |
51120 KB |
Output is correct |
84 |
Correct |
157 ms |
49228 KB |
Output is correct |
85 |
Correct |
291 ms |
52400 KB |
Output is correct |
86 |
Correct |
175 ms |
43696 KB |
Output is correct |
87 |
Correct |
166 ms |
43776 KB |
Output is correct |
88 |
Correct |
187 ms |
47540 KB |
Output is correct |
89 |
Correct |
206 ms |
48744 KB |
Output is correct |
90 |
Correct |
256 ms |
46144 KB |
Output is correct |
91 |
Correct |
259 ms |
47292 KB |
Output is correct |
92 |
Correct |
277 ms |
48952 KB |
Output is correct |
93 |
Correct |
239 ms |
49188 KB |
Output is correct |
94 |
Correct |
216 ms |
44412 KB |
Output is correct |
95 |
Correct |
132 ms |
44800 KB |
Output is correct |
96 |
Correct |
111 ms |
45712 KB |
Output is correct |
97 |
Correct |
110 ms |
24132 KB |
Output is correct |
98 |
Correct |
249 ms |
48736 KB |
Output is correct |
99 |
Correct |
198 ms |
49076 KB |
Output is correct |
100 |
Correct |
37 ms |
4872 KB |
Output is correct |
101 |
Correct |
281 ms |
48320 KB |
Output is correct |
102 |
Correct |
172 ms |
36156 KB |
Output is correct |
103 |
Correct |
209 ms |
37792 KB |
Output is correct |
104 |
Correct |
281 ms |
44708 KB |
Output is correct |