#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct dsu {
vector<int> par;
vector<vector<int>> el;
dsu(int n) : par(n), el(n) {
for (int i = 0; i < n; i++) par[i] = i, el[i] = {i};
}
int get(int i) {
return par[i] == i ? par[i] : par[i] = get(par[i]);
}
void merge(int a, int b) {
a = get(a);
b = get(b);
if (el[a].size() < el[b].size())
swap(a, b);
if (a != b) {
par[b] =a;
for (int x : el[b])
el[a].push_back(x);
}
}
};
int main() {
int n, m;
cin >> n >> m;
vector s(n, 0);
for (int& i : s) cin >> i;
vector<int> ix(n);
for (int i{}; i < n ;i++) ix[i] = i;
stable_sort(ix.begin(), ix.end(), [&](int a, int b) {
return s[a] > s[b];
});
vector<int> jx(n);
for (int i = 0; i < n; i ++)
jx[ix[i]] = i;
stable_sort(s.begin(), s.end(), greater{});
vector<vector<int>> adj(n);
for (int i = 0; i < m ;i++) {
int u, v;
cin >> u >> v;
u--;v--;
adj[jx[u]].push_back(jx[v]);
adj[jx[v]].push_back(jx[u]);
}
//for (int i : ix) cout << i << ' ';cout << endl;
//for (int i : jx) cout << i << ' ';cout << endl;
//for (int i : s) cout << i << ' ';cout << endl;
string res(n, '?');
vector<int> back(n, -1);
dsu cc(n);
for (int i =n -1; i >= 0;i --) {
for (int j : adj[i] ){
if (j > i)
cc.merge(i, j);
}
ll sum = 0;
for (int j : cc.el[cc.get(i)]) {
sum += s[j];
auto it = lower_bound(adj[j].begin(), adj[j].end(), i) - 1;
if (it >= adj[j].begin())
back[i] = max(back[i], *it);
}
if (back[i] != -1 && s[back[i]] > sum)
back[i] = -1;
if (back[i] == -1) {
if (i == 0)
res[i] = '1';
else res[i] = '0';
}
}
string ans(n, '?');
for (int i = 1; i < n;i++) {
if (back[i] != -1) res[i] = res[back[i]];
}
for (int i = 0; i < n; i++) {
ans[ix[i]] = res[i];
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |