#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
int par[100'005], sz[100'005], bad[100'005];
ll cnt[100'005];
vector<int> adj[100'005];
pair<int, int> find(int u) {
if (par[u] == u) {
return {u, bad[u]};
}
pair<int, int> v = find(par[u]);
bad[u] |= v.second;
par[u] = v.first;
return {par[u], bad[u]};
}
void join(int u, int v) {
u = find(u).first, v = find(v).first;
if (u == v) return;
par[v] = u, sz[u] += sz[v], cnt[u] += cnt[v];
for (auto nxt : adj[v]) {
int x = find(nxt).first;
if (x != u) {
adj[u].push_back(x);
}
}
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
par[i] = i, sz[i] = 1, bad[i] = 0;
cin >> cnt[i];
}
for (int i = 0, u, v; i < m; i++) {
cin >> u >> v;
u--, v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
priority_queue<pair<ll, int>> pq;
for (int i = 0; i < n; i++) {
pq.push({-cnt[i], i});
}
while (pq.size()) {
int node = pq.top().second;
ll val = -pq.top().first;
pq.pop();
if (node != par[node]) {
continue;
}
if (val != cnt[node]) {
continue;
}
if (sz[node] == n) {
continue;
}
int x = -1;
for (auto nxt : adj[node]) {
if (find(nxt).first != node && val >= cnt[find(nxt).first]) {
x = find(nxt).first;
break;
}
}
if (x == -1) {
bad[node] = 1;
continue;
}
join(node, x);
int New = find(node).first;
pq.push({-cnt[New], New});
}
for (int i = 0; i < n; i++) {
cout << !find(i).second;
}
cout << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4712 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4700 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Runtime error |
13 ms |
9308 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Runtime error |
12 ms |
9556 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Runtime error |
12 ms |
9092 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4712 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4700 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |