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>
using namespace std;
typedef long long int64;
const int maxn = 4e5 + 2;
int a[maxn], dsu[maxn];
int64 sum[maxn];
vector <pair <int, int> > ad [maxn];
vector <int> comp [maxn];
int rs [maxn];
int dad (int x) {
return dsu[x] = (x == dsu[x] ? x: dad(dsu[x]));
}
int main() {
int n,m;
cin >> n >> m;
vector <pair <int, int> > v;
for (int i = 1; i <= n; i++){
cin >> a[i];
dsu[i] = i;
sum[i] = a[i];
comp[i].push_back(i);
v.push_back({a[i], i});
}
for (int i = 1; i <= m; i++){
int x,y;
cin >> x >> y;
ad[x].push_back({a[y], y});
ad[y].push_back({a[x], x});
}
set <pair <int, int> > s;
sort(v.begin(), v.end());
for (auto [val, x]: v) {
sort(ad[x].rbegin(), ad[x].rend());
while (!ad[x].empty() && ad[x].back().first <= val) {
int y = ad[x].back().second;
int p1 = dad(x), p2 = dad(y);
// cout << x << " " << y << p1 << " " << p2 << "\n";
if (val > sum[p2]) comp[p2].clear();
if (p1 != p2) {
dsu[p2] = p1;
sum[p1] += sum[p2];
if (comp[p1].size() < comp[p2].size()) swap(comp[p1], comp[p2]);
for (int i: comp[p2]) comp[p1].push_back(i);
}
ad[x].pop_back();
}
}
map <int, int> dd;
for (int i = 1; i <= n; i++){
if (!dd.count(dad(i))) {
dd[i] = 1;
for (int j: comp[dad(i)]) rs[j] = 1;
}
}
for (int i = 1; i <= n; i++) cout << rs[i] << "";
return 0;
}
# | 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... |