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;
vector<vector<int>>g;
vector<int>num;
vector<long long>cnt;
vector<int>canTraverse; /// 0-unchecked, 1-false, 2-true
void calc(int u, int par){
cnt[u] = num[u];
for(int v : g[u]){
if(v != par){
calc(v, u);
cnt[u] += cnt[v];
}
}
}
void dfs(int u, int par){
if(canTraverse[par] == 1)canTraverse[u] = 1;
else{
canTraverse[u] = (cnt[u] >= num[par]) + 1;
}
for(int v : g[u]){
if(v != par){
dfs(v, u);
}
}
}
int main()
{
int n, m;
cin >> n >> m;
g.resize(n + 1);
num.resize(n + 1);
cnt.resize(n + 1);
canTraverse.resize(n + 1);
for(int i = 1;i <= n;++i)cin >> num[i];
for(int i = 0;i < m;++i){
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
calc(1, 1);
dfs(1, 1);
for(int i = 1;i <= n;++i){
if(canTraverse[i] == 2)cout << 1;
else cout << 0;
}
}
# | 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... |