#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
struct dsu{
vector<int> p, sz;
vector<bool> out;
vector<vector<int>> all;
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);
out.assign(n + 1, 1);
all.resize(n + 1);
for (int i = 1; i <= n; i++){
p[i] = i;
sz[i] = 1;
s[i] = x[i];
all[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: all[x]) all[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(b);
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 = 1; k <= n; k++){
int g = T.get(k);
if (k != g || T.s[k] >= nxt) continue;
for (int v: T.all[k]){
T.out[v] = 0;
}
}
i = j;
}
for (int i = 1; i <= n; i++){
cout<<T.out[i];
}
cout<<"\n";
}
# |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
7 ms |
604 KB |
Output is correct |
5 |
Correct |
7 ms |
772 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
5 ms |
604 KB |
Output is correct |
8 |
Correct |
4 ms |
668 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
7 ms |
860 KB |
Output is correct |
11 |
Correct |
8 ms |
604 KB |
Output is correct |
12 |
Correct |
5 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
1018 ms |
27372 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1089 ms |
26716 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
178 ms |
30580 KB |
Output is correct |
3 |
Correct |
187 ms |
35668 KB |
Output is correct |
4 |
Correct |
172 ms |
36948 KB |
Output is correct |
5 |
Correct |
142 ms |
35940 KB |
Output is correct |
6 |
Correct |
126 ms |
33228 KB |
Output is correct |
7 |
Correct |
93 ms |
33760 KB |
Output is correct |
8 |
Correct |
85 ms |
33800 KB |
Output is correct |
9 |
Correct |
75 ms |
18896 KB |
Output is correct |
10 |
Correct |
160 ms |
35200 KB |
Output is correct |
11 |
Correct |
139 ms |
35280 KB |
Output is correct |
# |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
7 ms |
604 KB |
Output is correct |
5 |
Correct |
7 ms |
772 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
5 ms |
604 KB |
Output is correct |
8 |
Correct |
4 ms |
668 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
7 ms |
860 KB |
Output is correct |
11 |
Correct |
8 ms |
604 KB |
Output is correct |
12 |
Correct |
5 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
1018 ms |
27372 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |