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 <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5 + 1;
ll S[maxn];
vector <int> adj[maxn];
bool vis[maxn];
bool ans[maxn];
ll sz[maxn];
void dfs(int s, int p) {
sz[s] = S[s];
vis[s] = true;
for (auto i : adj[s]) {
if (vis[i])
continue;
dfs(i, s);
sz[s] += sz[i];
}
}
vector <int> v;
void dfs2(int s, int p) {
for (auto i : adj[s]) {
if (i == p)
continue;
dfs2(i, s);
}
if (sz[s] >= S[p])
v.push_back(s);
if (p == 1) {
if (sz[s] >= S[1]) {
for (auto j : v)
ans[j] = true;
}
}
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> S[i];
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1, 1);
for (auto i : adj[1]) {
dfs2(i, 1);
}
ans[1] = 1;
for (int i = 1; i <= n; i++)
cout << ans[i];
cout << '\n';
}
# | 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... |