#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct dsu{
vector<int> p, sz;
vector<bool> ban, out;
vector<vector<int>> st;
vector<ll> s;
int n;
dsu(int ns, vector<int>& x){
n = ns;
p.resize(n + 1);
sz.resize(n + 1);
s.resize(n + 1);
ban.resize(n + 1);
out.assign(n + 1, 1);
st.resize(n + 1);
for (int i = 1; i <= n; i++){
p[i] = i;
sz[i] = 1;
s[i] = x[i];
st[i] = {i};
}
}
int get(int v){
if (p[v] != v){
p[v] = get(p[v]);
}
return p[v];
}
void unite(int x, int y){
x = get(x); y = get(y);
if (x == y) return;
if (sz[x] > sz[y]){
swap(x, y);
}
p[x] = y;
sz[y] += sz[x];
for (int i: st[x]) st[y].push_back(i);
s[y] += s[x];
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m; cin>>n>>m;
vector<int> x(n + 1), p = {0};
for (int i = 1; i <= n; i++){
cin>>x[i];
p.push_back(i);
}
auto cmp = [&](int i, int j){
return x[i] < x[j];
};
sort(p.begin(), p.end(), cmp);
vector<int> g[n + 1];
while (m--){
int a, b; cin>>a>>b;
g[a].push_back(a);
g[b].push_back(a);
}
int i = 1;
dsu T(n, x);
while (i <= n){
int j = i;
while (j <= n && x[p[i]] == x[p[j]]){
j++;
}
for (int k = i; k < j; k++){
int v = p[k];
for (int u: g[v]){
if (x[u] <= x[v]){
T.unite(u, v);
}
}
}
if (j > n) break;
int nxt = x[p[j]];
for (int k = i; k < j; k++){
int v = p[k], g = T.get(v);
ll s = T.s[g];
if (s < nxt){
if (T.ban[g]) continue;
T.ban[g] = true;
for (int u: T.st[v]){
T.out[u] = 0;
}
}
}
i = j;
}
for (int i = 1; i <= n; i++){
cout<<T.out[i];
}
cout<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
103 ms |
27680 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
164 ms |
27224 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
157 ms |
27696 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |