#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N = 2e5 + 69;
int n, m, a[N], p[N], sz[N], sum[N], vis[N], ans[N];
vector<int> g[N], can[N];
int root(int v) {
if (p[v] == v)
return v;
return p[v] = root(p[v]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n >> m;
for (int i = 1;i <= n;i++) {
cin >> a[i];
p[i] = i, sz[i] = 1;
sum[i] = a[i];
can[i].push_back(i);
}
vector<tuple<int, int, int>> edges;
for (int i = 1;i <= m;i++) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
int c = max(a[x], a[y]);
edges.push_back({c, x, y});
}
sort(edges.begin(), edges.end());
for (auto u : edges) {
int a, b, c;
tie(c, a, b) = u;
int x = root(a);
int y = root(b);
if (x != y) {
if (sum[x] >= c && sum[y] >= c) {
if (sz[x] < sz[y])
swap(x, y);
for (auto j : can[y])
can[x].push_back(j);
p[y] = x;
sz[x] += sz[y];
sum[x] += sum[y];
}
else if (sum[x] >= c) {
p[y] = x;
sum[x] += sum[y];
sz[x] += sz[y];
}
else {
assert(sum[y] >= c);
p[x] = y;
sum[y] += sum[x];
sz[y] += sz[x];
}
}
}
int ok = 1;
for (int i = 2;i <= n;i++)
ok &= (root(i) == root(i - 1));
assert(ok);
for (auto j : can[root(1)])
ans[j] = 1;
for (int i = 1;i <= n;i++)
cout << ans[i];
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Runtime error |
14 ms |
26204 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Runtime error |
120 ms |
59904 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Runtime error |
140 ms |
59096 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Runtime error |
148 ms |
59280 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Runtime error |
14 ms |
26204 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |