#include <iostream>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>
using i64 = int64_t;
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
i64 n, m;
std::cin >> n >> m;
std::vector<i64> a(n);
for (i64 i = 0; i < n; i++) std::cin >> a[i];
std::vector<std::vector<i64>> adj(n);
std::vector<std::vector<i64>> children(n);
for (i64 i = 0; i < m; i++) {
i64 u, v;
std::cin >> u >> v;
u--, v--;
adj[u].push_back(v);
adj[v].push_back(u);
children[std::min(u, v)].push_back(std::max(u, v));
}
if (n <= 2000 && m <= 2000) {
std::string result;
result.reserve(n);
std::vector<i64> visited(n);
for (i64 i = 0; i < n; i++) {
struct Node {
i64 size;
i64 idx;
bool operator<(const Node &rhs) const {
return std::tie(rhs.size, idx) < std::tie(size, rhs.idx);
}
};
std::priority_queue<Node> q;
std::fill(visited.begin(), visited.end(), false);
visited[i] = true;
i64 mass = a[i];
q.push(Node{.size = 0, .idx = i});
while (!q.empty()) {
Node node = q.top();
if (node.size > mass) break;
mass += node.size;
q.pop();
for (i64 j : adj[node.idx]) {
if (!visited[j]) {
visited[j] = true;
q.push(Node{.size = a[j], .idx = j});
}
}
}
result.push_back(q.empty() ? '1' : '0');
}
std::cout << result;
} else {
std::string result(n, '0');
std::vector<i64> sizes(n);
for (i64 i = n - 1; i >= 0; i--) {
sizes[i] = a[i];
for (i64 j : children[i]) {
sizes[i] += sizes[j];
}
}
result[0] = '1';
for (i64 i = 0; i < n; i++) {
if (result[i] == '1') {
for (i64 j : children[i]) {
if (sizes[j] >= a[i]) {
result[j] = '1';
}
}
}
}
std::cout << result;
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
174 ms |
532 KB |
Output is correct |
5 |
Correct |
151 ms |
580 KB |
Output is correct |
6 |
Correct |
230 ms |
548 KB |
Output is correct |
7 |
Correct |
164 ms |
564 KB |
Output is correct |
8 |
Correct |
119 ms |
528 KB |
Output is correct |
9 |
Correct |
221 ms |
596 KB |
Output is correct |
10 |
Correct |
70 ms |
596 KB |
Output is correct |
11 |
Correct |
68 ms |
592 KB |
Output is correct |
12 |
Correct |
71 ms |
588 KB |
Output is correct |
13 |
Correct |
112 ms |
596 KB |
Output is correct |
14 |
Correct |
95 ms |
564 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 |
175 ms |
24668 KB |
Output is correct |
4 |
Correct |
161 ms |
24780 KB |
Output is correct |
5 |
Correct |
190 ms |
23952 KB |
Output is correct |
6 |
Correct |
178 ms |
24528 KB |
Output is correct |
7 |
Correct |
187 ms |
24600 KB |
Output is correct |
8 |
Correct |
253 ms |
24552 KB |
Output is correct |
9 |
Correct |
177 ms |
24780 KB |
Output is correct |
10 |
Correct |
76 ms |
22600 KB |
Output is correct |
11 |
Correct |
92 ms |
22616 KB |
Output is correct |
12 |
Correct |
179 ms |
24652 KB |
Output is correct |
13 |
Correct |
147 ms |
25696 KB |
Output is correct |
14 |
Correct |
152 ms |
25676 KB |
Output is correct |
15 |
Correct |
181 ms |
25832 KB |
Output is correct |
16 |
Correct |
86 ms |
25404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
174 ms |
25548 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
175 ms |
24448 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
174 ms |
532 KB |
Output is correct |
5 |
Correct |
151 ms |
580 KB |
Output is correct |
6 |
Correct |
230 ms |
548 KB |
Output is correct |
7 |
Correct |
164 ms |
564 KB |
Output is correct |
8 |
Correct |
119 ms |
528 KB |
Output is correct |
9 |
Correct |
221 ms |
596 KB |
Output is correct |
10 |
Correct |
70 ms |
596 KB |
Output is correct |
11 |
Correct |
68 ms |
592 KB |
Output is correct |
12 |
Correct |
71 ms |
588 KB |
Output is correct |
13 |
Correct |
112 ms |
596 KB |
Output is correct |
14 |
Correct |
95 ms |
564 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
175 ms |
24668 KB |
Output is correct |
18 |
Correct |
161 ms |
24780 KB |
Output is correct |
19 |
Correct |
190 ms |
23952 KB |
Output is correct |
20 |
Correct |
178 ms |
24528 KB |
Output is correct |
21 |
Correct |
187 ms |
24600 KB |
Output is correct |
22 |
Correct |
253 ms |
24552 KB |
Output is correct |
23 |
Correct |
177 ms |
24780 KB |
Output is correct |
24 |
Correct |
76 ms |
22600 KB |
Output is correct |
25 |
Correct |
92 ms |
22616 KB |
Output is correct |
26 |
Correct |
179 ms |
24652 KB |
Output is correct |
27 |
Correct |
147 ms |
25696 KB |
Output is correct |
28 |
Correct |
152 ms |
25676 KB |
Output is correct |
29 |
Correct |
181 ms |
25832 KB |
Output is correct |
30 |
Correct |
86 ms |
25404 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Incorrect |
174 ms |
25548 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |