This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
#include <utility>
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));
}
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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |