# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1075913 | NeroZein | Simurgh (IOI17_simurgh) | C++17 | 558 ms | 604 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 "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> find_roads(int n, vector<int> eu, vector<int> ev) {
int cc;
vector<int> p(n), sz(n);
function<int(int)> get = [&](int v) {
return p[v] = (p[v] == v ? v : get(p[v]));
};
auto unite = [&](int u, int v) {
u = get(u); v = get(v);
if (u == v) {
return false;
}
if (sz[u] > sz[v]) {
swap(u, v);
}
--cc;
p[u] = v;
sz[v] += sz[u];
return true;
};
auto init_dsu = [&]() {
cc = n;
iota(p.begin(), p.end(), 0);
fill(sz.begin(), sz.end(), 1);
};
int m = (int) eu.size();
for (int i = 0; i < (1 << m); ++i) {
init_dsu();
bool ok = true;
vector<int> in_tree;
for (int j = 0; j < m; ++j) {
if (i >> j & 1) {
in_tree.push_back(j);
ok &= unite(eu[j], ev[j]);
}
}
if (cc > 1 || !ok) {
continue;
}
assert(in_tree.size() == n - 1);
if (count_common_roads(in_tree) == n - 1) {
return in_tree;
}
}
assert(false);
}
//~ int common = count_common_roads(r);
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... |