#include <bits/stdc++.h>
#include "simurgh.h"
#ifdef ONPC
#include "t_debug.cpp"
#else
#define debug(...) 42
#endif
#define sz(a) ((int)(a).size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll INFL = 1e18;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; }
const int N = 2e5, LOGN = 17, MOD = 1e9+7;
struct DSU {
int n;
vector<int> parent;
vector<int> size;
DSU(int n) : n(n), parent(n), size(n) {
iota(parent.begin(), parent.end(), 0);
}
int get(int i) {
return parent[i] == i ? i : parent[i] = get(parent[i]);
}
void merge(int v, int u) {
v = get(v);
u = get(u);
if (u == v) return;
if (size[v] < size[u]) swap(v, u);
parent[v] = u;
size[v] += size[u];
}
};
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
int m = sz(u);
vector<pair<int,int>> edges(m);
for (int i = 0; i < m; i++) {
edges.emplace_back(u[i], v[i]);
}
for (int i = 0; i < (1 << m); i++) {
if (__builtin_popcount(i) != n - 1) continue;
vector<int> cur;
DSU cc(n);
for (int j = 0; j < m; j++) {
if (i & (1 << j)) {
if (cc.get(u[j]) == cc.get(v[j]))
break;
cc.merge(u[j], v[j]);
cur.push_back(j);
}
}
if (cur.size() == n-1 && count_common_roads(cur) == n-1) return cur;
}
assert(false);
}
/*
█████ █████ ███ ████
▒▒███ ▒▒███ ▒▒▒ ▒▒███
███████ ████████ ███████ ████ ▒███ █████ ████ ██████ ████████
███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███ ▒███ ▒▒███ ▒███ ███▒▒███▒▒███▒▒███
▒███ ▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒
▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███
▒▒████████ █████ ▒▒████████ █████ █████ ▒▒███████ ▒▒██████ █████
▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒███ ▒▒▒▒▒▒ ▒▒▒▒▒
███ ▒███
▒▒██████
▒▒▒▒▒▒
*/
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:59:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
59 | if (cur.size() == n-1 && count_common_roads(cur) == n-1) return cur;
| ~~~~~~~~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
212 KB |
correct |
2 |
Correct |
27 ms |
292 KB |
correct |
3 |
Correct |
26 ms |
212 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
0 ms |
304 KB |
correct |
6 |
Correct |
2 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
304 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
11 ms |
304 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
212 KB |
correct |
2 |
Correct |
27 ms |
292 KB |
correct |
3 |
Correct |
26 ms |
212 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
0 ms |
304 KB |
correct |
6 |
Correct |
2 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
304 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
11 ms |
304 KB |
correct |
14 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
212 KB |
correct |
2 |
Correct |
27 ms |
292 KB |
correct |
3 |
Correct |
26 ms |
212 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
0 ms |
304 KB |
correct |
6 |
Correct |
2 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
304 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
11 ms |
304 KB |
correct |
14 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
212 KB |
correct |
2 |
Correct |
27 ms |
292 KB |
correct |
3 |
Correct |
26 ms |
212 KB |
correct |
4 |
Correct |
1 ms |
212 KB |
correct |
5 |
Correct |
0 ms |
304 KB |
correct |
6 |
Correct |
2 ms |
212 KB |
correct |
7 |
Correct |
1 ms |
304 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
11 ms |
304 KB |
correct |
14 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
15 |
Halted |
0 ms |
0 KB |
- |