#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
ll cnt[N], p[N], c[N], mx[N];
set<int> s[N];
vector<int> adj[N];
int get(int a) {return p[a] = (p[a] == a ? a : get(p[a]));}
void uni(int a, int b) {
a = get(a), b = get(b);
if(a == b) return;
p[a] = b;
if(cnt[a] >= c[b]) {
for(auto x: s[a]) s[b].insert(x);
}
cnt[b] += cnt[a];
}
int main() {
int n, m; cin >> n >> m;
vector<pair<int, int>> paiu;
for(int i = 0; i < n; ++i) {
cin >> c[i];
paiu.push_back({c[i], i});
}
for(int i = 0; i < n; ++i) {
p[i] = i;
cnt[i] = c[i];
s[i].insert(i);
}
sort(paiu.begin(), paiu.end());
vector<bool> vis(n, false);
for(int i = 0; i < m; ++i) {
int u, v; cin >> u >> v; --u, --v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 0; i < n; ++i) {
int u = paiu[i].second;
for(int v: adj[u]) {
if(!vis[v]) continue;
uni(v, u);
}
vis[u] = true;
}
vector<int> ans(n, 0);
for(auto x: s[paiu.back().second]) ans[x] = 1;
for(auto x: ans) cout << x;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
20 ms |
28912 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
14396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
14396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
14396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
75 ms |
44828 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
20 ms |
28912 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |