이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
bool ok[200001];
vector <int> adj[200001];
int cnt[200001], sze[200001];
void dfs (int pos, int par) {
sze[pos] = cnt[pos];
for (auto j : adj[pos]) {
if (j != par) {
dfs(j, pos);
sze[pos] += sze[j];
}
}
}
void dfs2 (int pos, int par) {
if (par != -1) {
if (sze[pos] < cnt[par]) return;
}
ok[pos] = 1;
for (auto j : adj[pos]) if (j != par) dfs2(j, pos);
}
signed main () {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> cnt[i];
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1, -1);
dfs2(1, -1);
for (int i = 1; i <= n; i++) cout << ok[i];
}
# | 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... |