#include"bits/stdc++.h"
using namespace std;
const int maxn = 200001;
const int sq = 5001;
vector<int> adj[maxn];
bitset<maxn> vis;
signed main () {
int n, m;
cin >> n >> m;
int a[n + 1];
for (int i = 1 ; i <= n ; i++) cin >> a[i];
for (int i = 0 ; i < m ; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
int vv[n + 1];
for (int i = 1 ; i <= n ; i++) {
int cntr = 0;
int vvv = a[i];
vector<int> visited;
visited.push_back(i);
vis = 0;
vis[i] = 1;
set<pair<int,int>> pq; // {value, index}
pq.insert({0, i});
while (pq.size() and cntr++ < sq) {
auto it = pq.lower_bound({vvv + 1, -1});
if (it == pq.begin()) break;
else it--;
auto [w, i] = *it;
pq.erase(it);
if (vvv >= w) vvv += w;
else break;
for (int j : adj[i]) {
if (!vis[j]) {
visited.push_back(j);
vis[j] = 1;
pq.insert({a[j], j});
}
}
}
vv[i] = vvv;
for (int j : visited) vis[j] = 0;
}
int v[n + 1];
for (int i = 1 ; i <= n ; i++) {
v[i] = i;
sort(adj[i].begin(), adj[i].end(), [&](int x, int y){return a[x] < a[y];});
}
int p[n + 1];
sort(v + 1, v + 1 + n, [&](int i, int j){return vv[i] < vv[j];});
for (int i = 1 ; i <= n ; i++) {
p[v[i]] = i;
}
int l = 0, r = n + 1;
while (r - l > 1) {
int m = (l + r) / 2;
// cerr << "m: " << m << endl;
priority_queue<pair<int,int>> pq; // {-value, index}
int cur = a[v[m]];
pq.push({0, v[m]});
vis = 0;
vis[v[m]] = 1;
int good = 0;
while (pq.size()) {
auto [w, i] = pq.top();
pq.pop();
w *= -1;
if (cur >= w) {
cur += w;
// cerr << "i: " << i << "\n";
good++;
} else {
continue;
}
for (int j : adj[i]) {
if (!vis[j]) {
vis[j] = 1;
pq.emplace(-a[j], j);
}
}
}
// cerr << good << endl;
if (good == n) r = m;
else l = m;
}
// cerr << "l: " << l << endl;
// for (int i = 1 ; i <= n ; i++) cout << vv[i] << " ";
// cout << endl;
for (int i = 1 ; i <= n ; i++) {
if (p[i] <= l) cout << 0;
else cout << 1;
}
cout << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
8 ms |
5076 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Incorrect |
847 ms |
14612 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
594 ms |
14464 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
665 ms |
14576 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
8 ms |
5076 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |