#include <bits/stdc++.h>
using namespace std;
int pr[200001],gs[200001],val[200001];
vector<int> adj[200001],ne[200001];
int find(int x){
if(x==pr[x])return x;
return pr[x] = find(pr[x]);
}
bool mergegroup(int a,int b){
a=find(a),b=find(b);
if(a==b)return 0;
pr[a]=b,gs[b]+=gs[a];
return 1;
}
int main(){
int n,m;
cin>>n>>m;
int arr[n];
vector<pair<int,int>> v;
for(int i = 0;i<n;i++){
cin>>arr[i];val[i] = 1;
pr[i] = i;gs[i] = arr[i];
v.push_back({arr[i],i});
}
sort(v.begin(),v.end());
for(int i = 0;i<m;i++){
int a,b;cin>>a>>b;
a--;b--;
if(a>b)swap(a,b);
if(arr[a]>arr[b])adj[a].push_back(b);
else if(arr[b]>arr[a])adj[b].push_back(a);
else adj[b].push_back(a);
}for(auto i:v){
int co = i.first , x = i.second;
for(auto j:adj[x]){
int lol = find(j) , xd = gs[lol];
if(mergegroup(lol,x)){
ne[x].push_back(lol);
if(xd<co){
queue<int> q;q.push(lol);
val[lol] = 0;
while(!q.empty()){
int xx = q.front();q.pop();
for(auto j:ne[xx]){
if(val[j]){
val[j] = 0;
q.push(j);
}
}
}
}
}
}
}
for(int i = 0;i<n;i++)cout<<val[i];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10840 KB |
Output is correct |
2 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Correct |
2 ms |
10844 KB |
Output is correct |
4 |
Incorrect |
4 ms |
10844 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10840 KB |
Output is correct |
2 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Incorrect |
180 ms |
23284 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10840 KB |
Output is correct |
2 |
Incorrect |
220 ms |
22956 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10840 KB |
Output is correct |
2 |
Incorrect |
227 ms |
22536 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10840 KB |
Output is correct |
2 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Correct |
2 ms |
10844 KB |
Output is correct |
4 |
Incorrect |
4 ms |
10844 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |