This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
* File created on 07/19/2022 at 15:02:09.
* Link to problem:
* Description:
* Time complexity: O()
* Space complexity: O()
* Status: ---
* Copyright: Ⓒ 2022 Francois Vogel
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pii pair<int, int>
#define f first
#define s second
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define size(x) (int)((x).size())
#define pb push_back
#define ins insert
#define cls clear
#define int ll
#define ll long long
#define ld long double
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int siz = 2e5+40;
int par [siz];
int sum [siz];
vi el [siz];
int gp(int x) {
if (par[x] == x) return x;
return par[x] = gp(par[x]);
}
void merge(int x, int y) {
x = gp(x);
y = gp(y);
if (x == y) return;
if (size(el[x]) < size(el[y])) swap(x, y);
par[y] = x;
sum[x] += sum[y];
for (int i : el[y]) el[x].pb(i);
}
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, nbE;
cin >> n >> nbE;
int val [n];
for (int i = 0; i < n; i++) {
cin >> val[i];
}
vi graph [n];
for (int i = 0; i < nbE; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
graph[a].pb(b);
graph[b].pb(a);
}
vector<pii> sorted;
for (int i = 0; i < n; i++) {
sorted.pb({val[i], i});
}
sort(all(sorted));
bool proc [n];
for (int i = 0; i < n; i++) {
proc[i] = false;
par[i] = i;
sum[i] = val[i];
el[i] = {i};
}
int res [n];
for (int i = 0; i < n; i++) {
res[i] = 1;
}
for (pii i : sorted) {
proc[i.s] = true;
for (int j : graph[i.s]) if (proc[j]) {
int x = gp(j);
if (sum[x] < i.f) {
for (int k : el[x]) {
res[k] = 0;
}
el[x].cls();
}
}
for (int j : graph[i.s]) if (proc[j]) {
merge(i.s, j);
}
}
for (int i : res) {
cout << i;
}
cout.flush();
int d = 0;
d++;
}
# | 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... |