#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int a[N];
int p[N];
bool s[N];
int ans[N];
int sum[N];
vector<int> g[N];
vector<int> sons[N];
int get (int v) {
if (p[v] < 0) return v;
return p[v] = get(p[v]);
}
void Dfs (int v) {
ans[v] = true;
for (int u : sons[v]) {
Dfs(u);
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
p[i] = -1;
sum[i] = a[i];
}
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
vector<int> ord(n);
iota(ord.begin(), ord.end(), 1);
sort(ord.begin(), ord.end(), [&](int u, int v) {
return a[u] < a[v];
});
for (int i = 0; i < n; ++i) {
int v = ord[i];
s[v] = true;
for (int u : g[v]) {
u = get(u);
if (!s[u] || u == v) {
continue;
}
if (sum[u] >= a[v]) {
sons[v].push_back(u);
}
sum[v] += sum[u];
p[u] = v;
}
}
Dfs(ord.back());
for (int i = 1; i <= n; ++i) {
cout << ans[i];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
7 ms |
9684 KB |
Output is correct |
4 |
Incorrect |
7 ms |
9780 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9728 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Incorrect |
133 ms |
22564 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
171 ms |
22328 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
180 ms |
22208 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
7 ms |
9684 KB |
Output is correct |
4 |
Incorrect |
7 ms |
9780 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |