이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 2e5 + 5;
int n, m;
int a[N], pr[N];
long long s[N];
bool lose[N];
int find(int u) {
if (u == pr[u]) {
return u;
}
int p = find(pr[u]);
lose[u] |= lose[pr[u]];
return pr[u] = p;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
pr[i] = i, s[i] = a[i];
}
vector<array<int, 2>> e;
while (m--) {
int x, y; cin >> x >> y;
if (a[x] > a[y]) {
swap(x, y);
}
e.push_back({x, y});
}
sort(e.begin(), e.end(), [&](const auto &i, const auto &j) {
return a[i[1]] < a[j[1]];
});
for (auto [u, v] : e) {
u = find(u);
if (u ^ v) {
lose[u] = s[u] < a[v];
pr[u] = v;
s[v] += s[u];
}
}
for (int i = 1; i <= n; ++i) {
find(i);
cout << (lose[i] ? 0 : 1);
}
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... |