# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1101685 | pubin06 | Stranded Far From Home (BOI22_island) | C++14 | 13 ms | 6320 KiB |
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
#define fi first
#define se second
#define sz(v) (int)(v).size()
using namespace std;
const int MXn = 100005;
const long long oo = 1e18;
const int MOD = 1e9 + 7;
int n, m, a[MXn], s[MXn], par[MXn];
bool cant[MXn];
int find_par(int u) {
if (u == par[u]) return u;
int r = find_par(par[u]);
cant[u] |= cant[par[u]];
return par[u] = r;
}
signed main(void) {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define TASK ""
if (ifstream(TASK".INP")) {
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i], s[i] = a[i];
iota(par + 1, par + 1 + n, 1);
vector<array<int, 3>> es;
for (int i = 1, u, v; i <= m; i++) {
cin >> u >> v;
if (a[u] < a[v]) swap(u, v);
es.push_back({a[u], u, v});
}
sort(begin(es), end(es));
for (auto e: es) {
int u = e[1], v = e[2];
u = find_par(u), v = find_par(v);
if (u ^ v) {
cant[v] = s[v] < a[u];
s[u] += s[v];
par[v] = u;
}
}
for (int i = 1; i <= n; i++) {
find_par(i); cout << (cant[i] ? 0 : 1);
}
return 0;
}
Compilation message (stderr)
# | 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... |