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;
const int N = 200005;
int n, m, s[N], fa[N], mx[N], ans[N];
long long sum[N];
vector<int> g[N], ch[N];
int getfa(int x) {
return fa[x] == x ? x : fa[x] = getfa(fa[x]);
}
void unite(int x, int y) {
x = getfa(x);
y = getfa(y);
if (x == y)
return;
if (sum[x] < mx[y])
ch[x].clear();
if (mx[x] > sum[y])
ch[y].clear();
if (ch[x].size() < ch[y].size())
swap(x, y);
for (int i : ch[y])
ch[x].push_back(i);
fa[y] = x;
mx[x] = max(mx[x], mx[y]);
sum[x] += sum[y];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> s[i];
vector<pair<int, int>> edg;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
edg.push_back({u, v});
}
sort(edg.begin(), edg.end(), [&](pair<int, int> x, pair<int, int> y) {
return max(s[x.first], s[x.second]) < max(s[y.first], s[y.second]);
});
for (int i = 1; i <= n; i++) {
fa[i] = i;
ch[i] = {i};
mx[i] = s[i];
sum[i] = s[i];
}
for (auto& e : edg) {
int u = e.first;
int v = e.second;
unite(u, v);
}
for (int i : ch[getfa(1)])
ans[i] = 1;
for (int i = 1; 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... |