#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
using namespace std;
const int NMAX = 200001;
class DSU{
public:
int parent[NMAX], cnt[NMAX], suma[NMAX];
vector <int> comp[NMAX];
int root(int x){
if(x == parent[x])
return x;
return parent[x] = root(parent[x]);
}
void merge(int a, int b){
a = root(a);
b = root(b);
if(a == b)
return;
if(cnt[a] < cnt[b])
swap(a, b);
cnt[a] += cnt[b];
parent[b] = a;
suma[a] += suma[b];
for(auto x : comp[b])
comp[a].push_back(x);
comp[b].clear();
}
}dsu;
vector <int> v[NMAX];
int rez[NMAX];
int p[NMAX];
int idx[NMAX];
bool cmp(int a, int b){
return p[a] < p[b];
}
int main()
{
int n, m, i;
cin >> n >> m;
for(i = 1; i <= n; i++){
cin >> p[i];
rez[i] = 1;
dsu.parent[i] = i;
dsu.cnt[i] = 1;
dsu.suma[i] = p[i];
dsu.comp[i].clear();
dsu.comp[i].push_back(i);
idx[i] = i;
}
for(i = 1; i <= m; i++){
int a, b;
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
sort(idx + 1, idx + n + 1, cmp);
for(i = 1; i <= n; i++){
int x = idx[i];
for(auto vecin : v[x]){
if(p[vecin] < p[x]){
int rV = dsu.root(vecin);
if(dsu.suma[rV] < p[x]){
for(auto y : dsu.comp[rV]){
rez[y] = 0;
}
dsu.comp[rV].clear();
}
}
if(p[vecin] <= p[x]){
dsu.merge(x, vecin);
}
}
}
for(i = 1; i <= n; i++){
cout << rez[i];
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9704 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Incorrect |
7 ms |
9844 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9708 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Incorrect |
342 ms |
29768 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
369 ms |
29772 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
380 ms |
29692 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9704 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Incorrect |
7 ms |
9844 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |