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 int long long
using namespace std;
struct Node {
int id, nbHab;
};
const int N = 2e5 + 42, MOD = 1e9 + 7;
bool ans[N];
Node node[N];
set<int> win[N];
vector<int> adj[N];
int n, m, par[N], sum[N];
int F(int i) {
if(par[i] == i)
return i;
return par[i] = F(par[i]);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++) {
node[i].id = i;
cin >> node[i].nbHab;
par[i] = i;
win[i].insert(i);
sum[i] = node[i].nbHab;
}
for(int i = 0; i < m; i++) {
int a, b; cin >> a >> b;
a--, b--;
if(a > b) swap(a, b);
if(node[a].nbHab > node[b].nbHab) swap(a, b);
adj[b].push_back(a);
}
sort(node, node + n,
[](Node a, Node b) {
if(a.nbHab == b.nbHab)
return a.id < b.id;
return a.nbHab < b.nbHab;
});
for(int i = 0; i < n; i++) {
int act = node[i].id;
for(int j : adj[act]) {
j = F(j);
if(j != act) {
if(sum[j] >= node[i].nbHab) {
if(win[j].size() > win[act].size())
swap(win[j], win[act]);
for(int id : win[j])
win[act].insert(id);
}
par[j] = act;
sum[act] += sum[j];
}
}
}
for(int i : win[F(node[n-1].id)])
ans[i] = true;
for(int i = 0; i < n; i++)
cout << ans[i];
}
# | 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... |