/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 200000;
int N, M;
int weight[N_MAX + 2];
vector <int> adj[N_MAX + 2];
int order[N_MAX + 2];
int root[N_MAX + 2];
ll sum[N_MAX + 2];
int findRoot (int u) {
return (root[u] == 0 ? u : root[u] = findRoot(root[u]));
}
bool seen[N_MAX + 2];
vector <int> sons[N_MAX + 2];
bool answer[N_MAX + 2];
void dfs (int u, int parent = 0) {
answer[u] = true;
for (int v : sons[u]) {
if (v != parent) {
dfs(v, u);
}
}
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
for (int u = 1; u <= N; u++) {
cin >> weight[u];
}
for (int i = 1; i <= M; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
iota(order + 1, order + N + 1, 1);
sort(order + 1, order + N + 1, [&] (const int &u, const int &v) {
return weight[u] < weight[v];
});
copy(weight + 1, weight + N + 1, sum + 1);
for (int i = 1; i <= N; i++) {
int u = order[i];
seen[u] = true;
for (int v : adj[u]) {
if (seen[v] == true) {
v = findRoot(v);
if (v != u) {
if (sum[v] >= weight[u]) {
sons[u].push_back(v);
}
root[v] = u;
sum[u] += weight[v];
}
}
}
}
dfs(order[N]);
for (int u = 1; u <= N; u++) {
cout << answer[u];
}
cout << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Incorrect |
7 ms |
9868 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Incorrect |
164 ms |
27992 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 |
209 ms |
26100 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9732 KB |
Output is correct |
2 |
Incorrect |
180 ms |
26692 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 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Incorrect |
7 ms |
9868 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |