#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[b] = a , gs[a]+=gs[b];
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(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 |
2 ms |
10840 KB |
Output is correct |
2 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Correct |
2 ms |
10676 KB |
Output is correct |
4 |
Incorrect |
4 ms |
10840 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Incorrect |
183 ms |
23244 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 |
252 ms |
22996 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 |
216 ms |
22368 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 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Correct |
2 ms |
10676 KB |
Output is correct |
4 |
Incorrect |
4 ms |
10840 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |