# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
941326 | prairie2022 | Stranded Far From Home (BOI22_island) | C++17 | 1 ms | 600 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>
using namespace std;
typedef long long ll;
#define F first
#define S second
vector<int> dsu[2]; // biggest in group, discard?, sum of popularity
inline int boss(int u, bool b){
int &bs = dsu[b][u];
if(bs==u) return u;
return bs = boss(bs, b);
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
fill(dsu, dsu+3, vector<int>(n+1));
dsu[1][0] = 0;
vector<pair<ll, int>> s(n+1);
for(int i=1; i<=n; i++){
cin >> s[i].F;
s[i].S = i;
}
vector<vector<int>> e(n+1);
while(m--){
int a, b;
cin >> a >> b;
if(s[a]<s[b]) swap(a, b);
e[a].push_back(b);
}
s[0] = {INT32_MAX, 0};
sort(s.begin(), s.end());
s.pop_back();
vector<ll> tot(n+1);
for(const auto &[num, i] : s){
dsu[0][i] = dsu[1][i] = i;
tot[i] = num;
for(int v: e[i]){
v = boss(v, 0);
if(v==i) continue;
dsu[0][v] = i;
dsu[1][v] = (tot[v]>=num)?i:0;
tot[i] += tot[v];
}
}
for(int i=1; i<=n; i++) cout << "10"[!boss(i, 1)];
}
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... |