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;
#define int long long
#define oo 100000000000000000
const int mx = 2e5 + 5;
int s[mx], sub[mx];
vector<int> g[mx];
bool ans[mx];
void dfs(int u, int p) {
sub[u] = s[u];
for(int v : g[u]) {
if(v == p) continue;
dfs(v,u);
sub[u] += sub[v];
}
}
void dfs2(int u,int p) {
if(!ans[p]) ans[u] = false;
else ans[u] = (sub[u] >= s[p]);
for(int v : g[u]) {
if(v == p) continue;
dfs2(v,u);
}
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n,m; cin >> n >> m;
for(int i = 1; i <= n; ++i) {
cin >> s[i];
}
for(int i = 1; i <= m; ++i) {
int u,v; cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
ans[0] = 1;
dfs(1,0);
dfs2(1,0);
for(int i = 1; i <= n; ++i) {
cout << ans[i];
}
return 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... |