#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 240 + 5;
vector<vector<pair<int, int>>> g(MAX_N);
bitset<MAX_N> vis;
bitset<MAX_N * MAX_N> invalid;
bitset<MAX_N * MAX_N> is_op;
vector<int> span, par, s, best_way, u, v;
int n;
void reset() {
for (int i = 0; i < n; i++) {
par[i] = i;
s[i] = 1;
}
}
int root(int x) {
if (x == par[x]) return x;
return par[x] = root(par[x]);
}
void join(int a, int b) {
a = root(a);
b = root(b);
if (a == b) return;
if (s[a] < s[b]) swap(a, b);
par[b] = a;
s[a] += s[b];
}
bool is(int a, int b) {
return root(a) == root(b);
}
bool works() {
for (auto to : span) {
const int st = u[to];
const int et = v[to];
if (is(st, et)) return false;
join(st, et);
}
return true;
}
void get_any(int node) {
vis[node] = 1;
for (auto [nxt, to] : g[node]) {
if (!vis[nxt]) {
vis[nxt] = 1;
span.emplace_back(to);
get_any(nxt);
}
}
}
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
::n = n;
::u = u;
::v = v;
const int m = v.size();
const int t = n - 1;
par = s = vector<int>(n);
for (int i = 0; i < m; i++) {
const int st = u[i];
const int et = v[i];
g[st].emplace_back(et, i);
g[et].emplace_back(st, i);
}
get_any(0);
int score = count_common_roads(span);
if (score == t) {
return span;
}
for (auto &edge : span) {
int starting_edge = edge;
bool swap = false;
reset();
best_way.clear();
for (auto add_back : span) {
if (add_back == edge) continue;
join(u[add_back], v[add_back]);
}
for (int i = 0; i < m; i++) {
const int st = u[i];
const int et = v[i];
if (is(st, et) == false && !invalid[i]) {
best_way.emplace_back(i);
}
}
//~ for (auto to :
vector<pair<int, int>> sc;
for (auto i : best_way) {
edge = i;
assert(!invalid[i]);
int nxt_score = count_common_roads(span);
sc.emplace_back(edge, nxt_score);
if (nxt_score > score) {
score = nxt_score;
swap = true;
break;
}
if (nxt_score < score) {
invalid[i] = 1;
}
}
if (score == t) {
return span;
}
if (!swap) {
edge = starting_edge;
for (auto [nxt, res] : sc) {
if (res < score) {
invalid[nxt] = 1;
}
}
} else {
for (auto [nxt, res] : sc) {
if (res <= score) {
invalid[nxt] = 1;
}
}
}
}
return span;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 KB |
correct |
5 |
Correct |
1 ms |
288 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
256 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
256 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 KB |
correct |
5 |
Correct |
1 ms |
288 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
256 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
256 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
14 |
Correct |
3 ms |
384 KB |
correct |
15 |
Correct |
3 ms |
416 KB |
correct |
16 |
Correct |
3 ms |
384 KB |
correct |
17 |
Correct |
3 ms |
384 KB |
correct |
18 |
Correct |
1 ms |
384 KB |
correct |
19 |
Correct |
3 ms |
384 KB |
correct |
20 |
Correct |
3 ms |
384 KB |
correct |
21 |
Correct |
2 ms |
384 KB |
correct |
22 |
Correct |
2 ms |
384 KB |
correct |
23 |
Correct |
2 ms |
384 KB |
correct |
24 |
Correct |
2 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
2 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
2 ms |
384 KB |
correct |
31 |
Correct |
2 ms |
384 KB |
correct |
32 |
Correct |
2 ms |
384 KB |
correct |
33 |
Correct |
2 ms |
384 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 KB |
correct |
5 |
Correct |
1 ms |
288 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
256 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
256 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
14 |
Correct |
3 ms |
384 KB |
correct |
15 |
Correct |
3 ms |
416 KB |
correct |
16 |
Correct |
3 ms |
384 KB |
correct |
17 |
Correct |
3 ms |
384 KB |
correct |
18 |
Correct |
1 ms |
384 KB |
correct |
19 |
Correct |
3 ms |
384 KB |
correct |
20 |
Correct |
3 ms |
384 KB |
correct |
21 |
Correct |
2 ms |
384 KB |
correct |
22 |
Correct |
2 ms |
384 KB |
correct |
23 |
Correct |
2 ms |
384 KB |
correct |
24 |
Correct |
2 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
2 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
2 ms |
384 KB |
correct |
31 |
Correct |
2 ms |
384 KB |
correct |
32 |
Correct |
2 ms |
384 KB |
correct |
33 |
Correct |
2 ms |
384 KB |
correct |
34 |
Correct |
236 ms |
1536 KB |
correct |
35 |
Correct |
251 ms |
1784 KB |
correct |
36 |
Correct |
166 ms |
1532 KB |
correct |
37 |
Correct |
13 ms |
384 KB |
correct |
38 |
Correct |
247 ms |
1912 KB |
correct |
39 |
Correct |
221 ms |
1788 KB |
correct |
40 |
Correct |
170 ms |
1408 KB |
correct |
41 |
Correct |
218 ms |
1820 KB |
correct |
42 |
Correct |
237 ms |
1916 KB |
correct |
43 |
Correct |
133 ms |
1280 KB |
correct |
44 |
Correct |
104 ms |
1016 KB |
correct |
45 |
Correct |
121 ms |
1024 KB |
correct |
46 |
Correct |
93 ms |
896 KB |
correct |
47 |
Correct |
44 ms |
640 KB |
correct |
48 |
Correct |
6 ms |
416 KB |
correct |
49 |
Correct |
15 ms |
384 KB |
correct |
50 |
Correct |
45 ms |
640 KB |
correct |
51 |
Correct |
120 ms |
1144 KB |
correct |
52 |
Correct |
106 ms |
896 KB |
correct |
53 |
Correct |
91 ms |
896 KB |
correct |
54 |
Correct |
127 ms |
1400 KB |
correct |
55 |
Correct |
124 ms |
1024 KB |
correct |
56 |
Correct |
123 ms |
1024 KB |
correct |
57 |
Correct |
124 ms |
1024 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
1 ms |
384 KB |
correct |
3 |
Runtime error |
24 ms |
4224 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 KB |
correct |
5 |
Correct |
1 ms |
288 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
256 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
256 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
14 |
Correct |
3 ms |
384 KB |
correct |
15 |
Correct |
3 ms |
416 KB |
correct |
16 |
Correct |
3 ms |
384 KB |
correct |
17 |
Correct |
3 ms |
384 KB |
correct |
18 |
Correct |
1 ms |
384 KB |
correct |
19 |
Correct |
3 ms |
384 KB |
correct |
20 |
Correct |
3 ms |
384 KB |
correct |
21 |
Correct |
2 ms |
384 KB |
correct |
22 |
Correct |
2 ms |
384 KB |
correct |
23 |
Correct |
2 ms |
384 KB |
correct |
24 |
Correct |
2 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
2 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
2 ms |
384 KB |
correct |
31 |
Correct |
2 ms |
384 KB |
correct |
32 |
Correct |
2 ms |
384 KB |
correct |
33 |
Correct |
2 ms |
384 KB |
correct |
34 |
Correct |
236 ms |
1536 KB |
correct |
35 |
Correct |
251 ms |
1784 KB |
correct |
36 |
Correct |
166 ms |
1532 KB |
correct |
37 |
Correct |
13 ms |
384 KB |
correct |
38 |
Correct |
247 ms |
1912 KB |
correct |
39 |
Correct |
221 ms |
1788 KB |
correct |
40 |
Correct |
170 ms |
1408 KB |
correct |
41 |
Correct |
218 ms |
1820 KB |
correct |
42 |
Correct |
237 ms |
1916 KB |
correct |
43 |
Correct |
133 ms |
1280 KB |
correct |
44 |
Correct |
104 ms |
1016 KB |
correct |
45 |
Correct |
121 ms |
1024 KB |
correct |
46 |
Correct |
93 ms |
896 KB |
correct |
47 |
Correct |
44 ms |
640 KB |
correct |
48 |
Correct |
6 ms |
416 KB |
correct |
49 |
Correct |
15 ms |
384 KB |
correct |
50 |
Correct |
45 ms |
640 KB |
correct |
51 |
Correct |
120 ms |
1144 KB |
correct |
52 |
Correct |
106 ms |
896 KB |
correct |
53 |
Correct |
91 ms |
896 KB |
correct |
54 |
Correct |
127 ms |
1400 KB |
correct |
55 |
Correct |
124 ms |
1024 KB |
correct |
56 |
Correct |
123 ms |
1024 KB |
correct |
57 |
Correct |
124 ms |
1024 KB |
correct |
58 |
Correct |
1 ms |
384 KB |
correct |
59 |
Correct |
1 ms |
384 KB |
correct |
60 |
Runtime error |
24 ms |
4224 KB |
Execution killed with signal 11 |
61 |
Halted |
0 ms |
0 KB |
- |