This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#define pii pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
using namespace std;
const int inf = 1e18;
void p(auto A){
for(auto e : A)cout << e << ' ';
cout << '\n';
}
void solve(){
int n, m; cin >> n >> m;
vector<int>A(n);
for(int i = 0; i< n; i++)cin >> A[i];
vector<vector<int>> g(n);
for(int i = 0; i< m; i++){
int c, d; cin >> c >> d; c--; d--;
g[c].pb(d);
g[d].pb(c);
}
vector<int> par(n, -1);
auto find = [&](auto&& self, int u)->int{
return par[u] < 0 ? u : par[u] = self(self, par[u]);
};
auto uni = [&](int u, int v)->bool{
u = find(find, u);
v = find(find, v);
if(u == v)return false;
par[u] += par[v];
par[v] = u;
return true;
};
vector<int> per(n);
iota(all(per), 0);
sort(all(per), [&](int i, int j)->bool{return A[i] < A[j];});
vector<vector<int>> tre(n);
vector<int> vis(n);
for(auto u : per){
vis[u] = 1;
for(auto v : g[u])if(vis[v])if(find(find, v) != u){
tre[u].pb(find(find,v));
uni(u, v);
}
}
vector<int>B = A;
for(auto u : per)for(auto v : tre[u])B[u] += B[v];
reverse(all(per));
vector<int> ans(n);
ans[per[0]] = 1;
for(auto u : per)for(auto v : tre[u])if(B[v] >= A[u])ans[v] = ans[u];
for(auto e : ans)cout << e;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin >> t;
while(t--)solve();
}
Compilation message (stderr)
island.cpp:15:8: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
15 | void p(auto A){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |