#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int MAXN = 2e5+5;
ll in[MAXN], sum[MAXN];
int par[MAXN];
bool marked[MAXN];
int find(int v)
{
int curr_par = v;
while(curr_par != par[curr_par])
{
if(marked[curr_par])
marked[v] = true;
curr_par = par[curr_par];
}
return curr_par;
}
void merge(int a, int b)
{
a = find(a), b = find(b);
if(a == b)
return ;
if(sum[a] < sum[b])
swap(a, b);
sum[a] += sum[b];
sum[b] = 0;
par[b] = a;
}
vector < vector< int > > adj(MAXN);
int main()
{
int n, m;
cin >> n >> m;
vector < pair<int, int> > sorted;
for(int i = 1; i <= n; i++) {
cin >> in[i];
sorted.push_back({in[i], i});
ans[i] = 1;
sum[i] = in[i];
par[i] = i;
}
sort(sorted.begin(), sorted.end());
for(int i = 1; i <= m; i++)
{
int f, s;
cin >> f >> s;
adj[f].push_back(s);
adj[s].push_back(f);
}
for(int i = 0; i < n; i++)
{
int idx = sorted[i].second;
for(int e : adj[idx])
{
if(in[e] <= in[idx]) {
int other = find(e);
if(sum[other] < in[idx])
marked[other] = true;
merge(other, idx);
}
}
}
for(int i = 1; i <= n; i++)
{
find(i);
cout << !marked[i];
}
cout << "\n";
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:44:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
44 | ans[i] = 1;
| ^~~
| abs