#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#define pii pair <int, int>
using namespace std;
const int NMAX = 2e5;
int v[NMAX + 1];
vector <int> adj[NMAX + 1];
int par[NMAX + 1];
int sum[NMAX + 1];
int Find(int x){
if(x == par[x]){
return x;
}
return par[x] = Find(par[x]);
}
void Join(int x, int y){
x = par[x];
y = par[y];
par[x] = y;
sum[y] += sum[x];
}
bool ins[NMAX + 1];
void Insert(int x){
ins[x] = true;
for(int vec : adj[x]){
if(ins[vec]){
Join(vec, x);
}
}
}
bool ans[NMAX + 1];
int main(){
int n, m;
cin >> n >> m;
vector <pii> aux;
priority_queue <pii, vector <pii>, greater <pii>> pq;
for(int i = 1; i <= n; i++){
cin >> v[i];
par[i] = i;
sum[i] = v[i];
aux.push_back({v[i], i});
pq.push({v[i], i});
ans[i] = 1;
}
for(int i = 1; i <= m; i++){
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
sort(aux.begin(), aux.end());
for(int i = 0; i < (int)aux.size(); i++){
int val = aux[i].first;
Insert(aux[i].second);
//cout << "-- " << aux[i].second << endl;
while(i + 1 < (int)aux.size() && aux[i + 1].first == aux[i].first){
Insert(aux[++i].second);
//cout << "-- " << aux[i].second << endl;
}
while(!pq.empty() && pq.top().first <= val){
int node = pq.top().second;
int x = pq.top().first;
pq.pop();
int s = sum[Find(node)];
if(s == x){
// cout << ">> " << node << ' ' << val << ' ' << x << ' ' << s << endl;
ans[node] = 0;
}else{
pq.push({node, s});
}
}
}
for(int i = 1; i <= n; i++){
cout << ans[i];
}
cout << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
6748 KB |
Output is correct |
3 |
Incorrect |
1 ms |
6748 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6924 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
6748 KB |
Output is correct |
3 |
Incorrect |
1 ms |
6748 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |