#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 2e5 + 5;
int n, m;
int a[N], pr[N];
long long s[N];
bool lose[N];
int find(int u) {
if (u == pr[u]) {
return u;
}
int p = find(pr[u]);
lose[u] |= lose[pr[u]];
return pr[u] = p;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
pr[i] = i, s[i] = a[i];
}
vector<array<int, 2>> e;
while (m--) {
int x, y; cin >> x >> y;
if (a[x] > a[y]) {
swap(x, y);
}
e.push_back({x, y});
}
sort(e.begin(), e.end(), [&](auto i, auto j) {
return a[i[1]] < a[j[1]];
});
for (auto [u, v] : e) {
u = find(u);
if (u ^ v) {
lose[u] = s[u] < a[v];
pr[u] = v;
s[v] += s[u];
}
}
for (int i = 1; i <= n; ++i) {
find(i);
cout << (lose[i] ? 0 : 1);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Runtime error |
255 ms |
524288 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
62 ms |
5580 KB |
Output is correct |
4 |
Correct |
47 ms |
8648 KB |
Output is correct |
5 |
Correct |
62 ms |
9504 KB |
Output is correct |
6 |
Correct |
63 ms |
9924 KB |
Output is correct |
7 |
Correct |
72 ms |
9928 KB |
Output is correct |
8 |
Correct |
67 ms |
9972 KB |
Output is correct |
9 |
Correct |
60 ms |
9928 KB |
Output is correct |
10 |
Correct |
45 ms |
9160 KB |
Output is correct |
11 |
Correct |
57 ms |
9928 KB |
Output is correct |
12 |
Correct |
53 ms |
8648 KB |
Output is correct |
13 |
Correct |
52 ms |
8420 KB |
Output is correct |
14 |
Correct |
48 ms |
8652 KB |
Output is correct |
15 |
Correct |
63 ms |
9988 KB |
Output is correct |
16 |
Correct |
44 ms |
9168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
68 ms |
5580 KB |
Output is correct |
3 |
Correct |
67 ms |
5664 KB |
Output is correct |
4 |
Correct |
52 ms |
5580 KB |
Output is correct |
5 |
Correct |
48 ms |
5592 KB |
Output is correct |
6 |
Correct |
71 ms |
5588 KB |
Output is correct |
7 |
Correct |
65 ms |
5580 KB |
Output is correct |
8 |
Correct |
70 ms |
10192 KB |
Output is correct |
9 |
Correct |
42 ms |
9160 KB |
Output is correct |
10 |
Incorrect |
51 ms |
9252 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
330 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Runtime error |
255 ms |
524288 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |