#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const int N = 200'005;
bool in[N], bad[N];
vector<int> adj[N];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
int a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = i;
}
sort(b, b + n, [&] (int i, int j) {return a[i] < a[j];});
reverse(b, b + n);
for (int i = 0, u, v; i < m; i++) {
cin >> u >> v;
u--, v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
int ans[n]{};
for (auto st : b) {
if (bad[st]) {
ans[st] = 0;
continue;
}
for (int i = 0; i < n; i++) {
in[i] = 0;
}
in[st] = 1;
priority_queue<pair<int, int>> pq;
for (auto nxt : adj[st]) {
pq.push({-a[nxt], nxt});
}
ll ttl = a[st];
while (pq.size()) {
int cost = -pq.top().first;
int node = pq.top().second;
pq.pop();
if (in[node]) continue;
if (ttl < cost) {
break;
}
ttl += cost;
in[node] = 1;
for (auto nxt : adj[node]) {
if (!in[nxt]) {
pq.push({-a[nxt], nxt});
}
}
}
int ok = 1;
for (int i = 0; i < n; i++) {
ok &= in[i];
}
if (!ok) {
for (int i = 0; i < n; i++) {
if (in[i]) {
bad[i] = 1;
}
}
}
ans[st] = ok;
if (!ok) break;
}
for (auto i : ans) {
cout << i;
}
cout << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Incorrect |
113 ms |
14328 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Execution timed out |
1031 ms |
14116 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Execution timed out |
1080 ms |
13908 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |