#include <bits/stdc++.h>
#define IO_OP ios::sync_with_stdio(0), cin.tie(0)
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 2e5 + 7;
int s[N], where[N], ans[N], pos[N];
ll sum[N];
vi who[N], alive[N];
vi G[N];
signed main()
{
IO_OP;
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> s[i];
vi p(n);
iota(ALL(p), 1);
sort(ALL(p), [&] (int a, int b) {
return s[a] < s[b];
});
for(int i = 0; i < n; i++)
pos[p[i]] = i;
for(int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
G[u].PB(v);
G[v].PB(u);
}
auto unite = [&] (int x, int y) {
if(SZ(who[x]) > SZ(who[y])) swap(x, y);
for(int u:who[x]) {
who[y].PB(x);
where[u] = y;
}
sum[y] += sum[x];
if(SZ(alive[x]) > SZ(alive[y]))
swap(alive[x], alive[y]);
for(int u:alive[x])
alive[y].PB(u);
};
for(int u:p) {
ans[u] = 1;
where[u] = u, who[u].PB(u), alive[u].PB(u), sum[u] = s[u];
vi cc;
for(int v:G[u]) if(pos[v] < pos[u])
cc.PB(where[v]);
sort(ALL(cc));
cc.resize(unique(ALL(cc)) - cc.begin());
for(int c:cc) if(sum[c] < s[u]) {
for(int v:alive[c])
ans[v] = 0;
alive[c].clear();
}
for(int c:cc)
unite(where[u], c);
}
for(int i = 1; i <= n; i++)
cout << ans[i];
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Correct |
9 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14324 KB |
Output is correct |
4 |
Correct |
10 ms |
14952 KB |
Output is correct |
5 |
Correct |
10 ms |
14640 KB |
Output is correct |
6 |
Correct |
9 ms |
14804 KB |
Output is correct |
7 |
Incorrect |
9 ms |
14932 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14404 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
191 ms |
42164 KB |
Output is correct |
4 |
Incorrect |
176 ms |
44620 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14400 KB |
Output is correct |
2 |
Correct |
354 ms |
42980 KB |
Output is correct |
3 |
Incorrect |
344 ms |
43076 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14404 KB |
Output is correct |
2 |
Incorrect |
403 ms |
43772 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Correct |
9 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14324 KB |
Output is correct |
4 |
Correct |
10 ms |
14952 KB |
Output is correct |
5 |
Correct |
10 ms |
14640 KB |
Output is correct |
6 |
Correct |
9 ms |
14804 KB |
Output is correct |
7 |
Incorrect |
9 ms |
14932 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |