#include <bits/stdc++.h>
#define int long long
//#define endl '\n'
using namespace std;
const int MAX = 2e5 + 5;
vector<int> adj[MAX];
int subtree[MAX], sum[MAX];
int s[MAX], ans[MAX];
void dfs_subtree(int u, int p){
subtree[u] = s[u];
for(auto v : adj[u]){
if(v == p) continue;
dfs_subtree(v, u);
subtree[u] += subtree[v];
}
}
void dfs(int u, int p){
for(auto v : adj[u]){
if(v == p) continue;
if(subtree[v] < s[u]) continue;
ans[v] = 1;
dfs(v, u);
}
}
signed main()
{
ios::sync_with_stdio(0);
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;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs_subtree(1, 0);
dfs(1, 0);
for(int i = 1; i <= n; i++){
cout<<ans[i];
}
cout<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
235 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
235 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |