#include"bits/stdc++.h"
using namespace std;
const int maxn = 200001;
const int sq = sqrt(maxn) / 2;
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[i] = 1;
set<pair<int,int>> pq; // {value, index}
pq.insert({0, i});
while (pq.size() and cntr++ < sq) {
auto it = pq.upper_bound({vvv, INT_MAX});
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
6 ms |
5088 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Incorrect |
603 ms |
14752 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
358 ms |
14608 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
412 ms |
14552 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
6 ms |
5088 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |