| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1365752 | retarde | Stranded Far From Home (BOI22_island) | C++20 | 270 ms | 82840 KiB |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
const int mod = 1e9 + 7;
const int inf = INTMAX_MAX;
const bool tc = false;
int n, m;
vi adj[200005]; int a[200005];
class DisjointSets {
private:
vector<int> parents;
vector<int> sizes;
public:
vector<int> sumsize;
vector<set<int>> cands;
DisjointSets(int size) : parents(size), sizes(size, 1), sumsize(size), cands(size) {
for (int i = 0; i < size; i++) {
parents[i] = i;
sumsize[i] = a[i];
cands[i].insert(i);
}
}
/** @return the "representative" node in x's component */
int find(int x) { return parents[x] == x ? x : (parents[x] = find(parents[x])); }
set<int> get(int x) { return cands[find(x)]; }
/** @return whether the merge changed connectivity */
bool unite(int x, int y) {
int x_root = find(x);
int y_root = find(y);
if (x_root == y_root) { return false; }
bool mrg = false;
if (a[x] <= sumsize[y_root]) {
mrg = true;
} else {
cands[y_root].clear();
}
if (sizes[x_root] < sizes[y_root]) { swap(x_root, y_root); }
for (auto &cd : cands[y_root]) cands[x_root].insert(cd);
sizes[x_root] += sizes[y_root];
parents[y_root] = x_root;
sumsize[x_root] += sumsize[y_root];
return true;
}
/** @return whether x and y are in the same connected component */
bool connected(int x, int y) { return find(x) == find(y); }
};
inline void solve() {
cin >> n >> m;
vector<pii> nodes;
for (int i = 0; i < n; i++) {
cin >> a[i];
nodes.pb({a[i], i});
}
for (int i = 0; i < m; i++) {
int x, y; cin >> x >> y;
x--; y--; adj[x].pb(y); adj[y].pb(x);
}
sort(all(nodes)); DisjointSets dsu(n);
for (auto &x : nodes) {
int u = x.second;
for (auto &v : adj[u]) {
if (a[v] > a[u]) continue;
if (dsu.connected(u, v)) continue;
dsu.unite(u, v);
}
}
string ans(n, '0');
for (auto &x : dsu.cands[dsu.find(0)]) ans[x] = '1';
cout << ans << '\n';
}
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
signed main() {
ios::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
//setIO();
int t = 1;
if (tc) {
cin >> t;
}
while (t--) {
solve();
}
}Compilation message (stderr)
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
