# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
702214 | lovrot | Stranded Far From Home (BOI22_island) | C++17 | 179 ms | 24684 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 <vector>
#include <cstdio>
#include <algorithm>
#define X first
#define Y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 2e5 + 10;
int n, m, to[N], U[N], sol[N];
ll S[N], SUM[N];
vector<int> g[N];
vector<pair<ll, int>> p;
int Find(int u) {
if(u == U[u]) return u;
return U[u] = Find(U[u]);
}
void Union(int u, int v) {
u = Find(u);
v = Find(v);
if(u == v) return;
U[v] = u;
SUM[u] += SUM[v];
if(!to[v] || S[to[v]] == S[v]) to[v] = u;
}
int main() {
for(int i = 0; i < N; i++) U[i] = i;
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) {
scanf("%lld", S + i);
p.pb({S[i], i});
}
sort(p.begin(), p.end());
for(int i = 0; i < m; i++) {
int u, v;
scanf("%d%d", &u, &v);
if(S[u] < S[v] || S[u] == S[v] && u < v) swap(u, v);
g[u].pb(v);
}
for(pair<ll, int> u : p) {
SUM[u.Y] = S[u.Y];
for(int v : g[u.Y]) Union(u.Y, v);
}
reverse(p.begin(), p.end());
to[p[0].Y] = 0;
SUM[0] = 0;
sol[0] = 1;
for(pair<ll, int> u : p)
if(sol[to[u.Y]] && SUM[u.Y] >= S[to[u.Y]]) sol[u.Y] = true;
for(int i = 1; i <= n; i++) printf("%d", sol[i]);
printf("\n");
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... |