#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
ll cnt[N], p[N], c[N];
set<ll> s[N];
vector<ll> adj[N];
ll get(ll a) {return p[a] = (p[a] == a ? a : get(p[a]));}
void uni(ll a, ll b, ll vb) {
a = get(a), b = get(b);
if(a == b) return;
bool swapped = false;
if((ll)s[a].size() > (ll)s[b].size()) {
swap(a, b);
swapped = true;
}
if(!swapped) {
if(cnt[a] >= vb) {
for(auto x: s[a]) s[b].insert(x);
}
} else if(cnt[b] >= vb){
for(auto x: s[a]) s[b].insert(x);
}
p[a] = b;
cnt[b] += cnt[a];
}
int main() {
int n, m; cin >> n >> m;
vector<pair<ll, ll>> 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) {
ll u = paiu[i].second;
for(int v: adj[u]) {
if(!vis[v]) continue;
uni(v, u, c[u]);
}
vis[u] = true;
}
vector<int> ans(n, 0);
for(auto x: s[get(paiu[n - 1].second)]) ans[x] = 1;
for(auto x: ans) cout << x;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14292 KB |
Output is correct |
2 |
Correct |
8 ms |
14412 KB |
Output is correct |
3 |
Correct |
9 ms |
14292 KB |
Output is correct |
4 |
Incorrect |
11 ms |
14628 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14392 KB |
Output is correct |
2 |
Correct |
8 ms |
14412 KB |
Output is correct |
3 |
Correct |
306 ms |
48520 KB |
Output is correct |
4 |
Incorrect |
288 ms |
49264 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14292 KB |
Output is correct |
2 |
Incorrect |
471 ms |
67656 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14292 KB |
Output is correct |
2 |
Incorrect |
426 ms |
54756 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14292 KB |
Output is correct |
2 |
Correct |
8 ms |
14412 KB |
Output is correct |
3 |
Correct |
9 ms |
14292 KB |
Output is correct |
4 |
Incorrect |
11 ms |
14628 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |