#include <bits/stdc++.h>
#define int long long
using namespace std;
int N,M,V[200001],X,Y,VIS[200001];
int R[200001],DSU[200001],SUM[200001];
vector<int>edges[200001];
set<int>DSU2[200001];
set<int>ZZ;
int FIND(int X){
if(DSU[X] == X)return X;
return FIND(DSU[X]);
}
int32_t main()
{
cin.tie(0),iostream::sync_with_stdio(0);
cin>>N>>M;
vector<pair<int,int>>FF;
for(int i = 0; i < N; i += 1){
cin>>V[i];
FF.push_back({V[i],i});
}
for(int i = 0; i < N; i += 1)DSU2[i].insert(i),DSU[i] = i,SUM[i] = V[i],R[i] = 1;
sort(FF.begin(),FF.end());
for(int i = 0; i < M; i += 1){
cin>>X>>Y;
edges[X - 1].push_back(Y - 1),edges[Y - 1].push_back(X - 1);
}
for(int i = 0 ;i < N; i += 1){
int IDX = FF[i].second, WE = FF[i].first, F2 = FIND(IDX);
//cout<<"lol"<<endl;
for(int l = 0; l < edges[IDX].size();l++){
if(V[edges[IDX][l]] > WE)continue;
int F1 = FIND(edges[IDX][l]);
if(F1 == F2)continue;
int S = SUM[F1];
//cout<<S<<' '<<WE<<endl;
if(S < WE){
for(auto itr = DSU2[F1].begin();itr!=DSU2[F1].end();itr++){
R[*itr] = 0;
}
DSU2[F1].clear();
}
//if(DSU2[F1].size() < DSU2[F2].size())swap(F1,F2);
SUM[F1] += SUM[F2];
DSU[F2] = F1;
SUM[F2] = 0;
for(auto itr = DSU2[F2].begin(); itr != DSU2[F2].end();itr++)
DSU2[F1].insert(*itr);
DSU2[F2].clear();
}
}
for(int i = 0; i < N; i += 1)cout<<R[i];
}
Compilation message
island.cpp: In function 'int32_t main()':
island.cpp:31:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int l = 0; l < edges[IDX].size();l++){
| ~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14384 KB |
Output is correct |
4 |
Incorrect |
8 ms |
14632 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14372 KB |
Output is correct |
3 |
Incorrect |
169 ms |
40764 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14396 KB |
Output is correct |
2 |
Incorrect |
247 ms |
39448 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14428 KB |
Output is correct |
2 |
Incorrect |
269 ms |
40500 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14384 KB |
Output is correct |
4 |
Incorrect |
8 ms |
14632 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |