#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e2 + 20;
const int maxm = maxn * maxn / 2;
vector<pair<int, int>> adj[maxn];
bool tree[maxm];
int flag[maxm];
int comp[maxn];
void dfs1(int u) {
flag[u] = true;
for (auto e: adj[u]) {
int v = e.first;
int id = e.second;
if (!flag[v]) {
tree[id] = true;
dfs1(v);
}
}
}
void dfs2(int u, int p) {
comp[u] = 1;
for (auto e: adj[u]) {
int v = e.first;
int id = e.second;
if (tree[id] && v != p) {
dfs2(v, u);
}
}
}
mt19937 gen(69420);
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
int m = u.size();
for (int i = 0; i < m; i++) {
adj[u[i]].emplace_back(v[i], i);
adj[v[i]].emplace_back(u[i], i);
}
vector<int> order(m);
for (int i = 0; i < m; i++) {
order[i] = i;
}
shuffle(order.begin(), order.end(), gen);
dfs1(0);
for (int i = 0; i < m; i++) {
flag[i] = -1;
}
vector<int> res;
for (int i = 0; i < m; i++) {
if (tree[i]) {
res.push_back(i);
}
}
while (true) {
for (int i = 0; i < n - 1; i++) {
if (flag[res[i]] == -1) {
tree[res[i]] = false;
res.erase(res.begin() + i);
break;
}
}
if ((int)res.size() == n - 1) {
break;
}
for (int i = 0; i < n; i++) {
comp[i] = 0;
}
dfs2(0, -1);
vector<pair<int, int>> cnt;
int good = -1;
for (int i = 0; i < m; i++) {
if (comp[u[i]] != comp[v[i]] && flag[i] == 1) {
good = i;
break;
}
}
if (good == -1) {
int mx = -1;
for (int k = 0; k < m; k++) {
int i = order[k];
if (comp[u[i]] != comp[v[i]] && flag[i] == -1) {
res.push_back(i);
cnt.emplace_back(count_common_roads(res), i);
res.pop_back();
mx = max(mx, cnt.back().first);
if ((int)cnt.size() >= 2 && cnt.back().first != cnt.end()[-2].first) {
break;
}
}
}
for (auto p: cnt) {
if (p.first == mx) {
good = p.second;
flag[p.second] = 1;
}
else {
flag[p.second] = 0;
}
}
}
tree[good] = true;
res.push_back(good);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Correct |
1 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
212 KB |
correct |
5 |
Correct |
0 ms |
212 KB |
correct |
6 |
Correct |
0 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
0 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
0 ms |
212 KB |
correct |
13 |
Correct |
0 ms |
212 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Correct |
1 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
212 KB |
correct |
5 |
Correct |
0 ms |
212 KB |
correct |
6 |
Correct |
0 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
0 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
0 ms |
212 KB |
correct |
13 |
Correct |
0 ms |
212 KB |
correct |
14 |
Correct |
2 ms |
340 KB |
correct |
15 |
Correct |
1 ms |
340 KB |
correct |
16 |
Correct |
1 ms |
340 KB |
correct |
17 |
Correct |
2 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
1 ms |
340 KB |
correct |
20 |
Correct |
1 ms |
328 KB |
correct |
21 |
Correct |
1 ms |
340 KB |
correct |
22 |
Correct |
1 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
360 KB |
correct |
24 |
Correct |
1 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
340 KB |
correct |
26 |
Correct |
1 ms |
340 KB |
correct |
27 |
Correct |
1 ms |
340 KB |
correct |
28 |
Correct |
1 ms |
340 KB |
correct |
29 |
Correct |
0 ms |
340 KB |
correct |
30 |
Correct |
1 ms |
340 KB |
correct |
31 |
Correct |
1 ms |
340 KB |
correct |
32 |
Correct |
1 ms |
340 KB |
correct |
33 |
Correct |
1 ms |
340 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Correct |
1 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
212 KB |
correct |
5 |
Correct |
0 ms |
212 KB |
correct |
6 |
Correct |
0 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
0 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
0 ms |
212 KB |
correct |
13 |
Correct |
0 ms |
212 KB |
correct |
14 |
Correct |
2 ms |
340 KB |
correct |
15 |
Correct |
1 ms |
340 KB |
correct |
16 |
Correct |
1 ms |
340 KB |
correct |
17 |
Correct |
2 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
1 ms |
340 KB |
correct |
20 |
Correct |
1 ms |
328 KB |
correct |
21 |
Correct |
1 ms |
340 KB |
correct |
22 |
Correct |
1 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
360 KB |
correct |
24 |
Correct |
1 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
340 KB |
correct |
26 |
Correct |
1 ms |
340 KB |
correct |
27 |
Correct |
1 ms |
340 KB |
correct |
28 |
Correct |
1 ms |
340 KB |
correct |
29 |
Correct |
0 ms |
340 KB |
correct |
30 |
Correct |
1 ms |
340 KB |
correct |
31 |
Correct |
1 ms |
340 KB |
correct |
32 |
Correct |
1 ms |
340 KB |
correct |
33 |
Correct |
1 ms |
340 KB |
correct |
34 |
Correct |
108 ms |
1628 KB |
correct |
35 |
Correct |
91 ms |
1572 KB |
correct |
36 |
Correct |
65 ms |
1368 KB |
correct |
37 |
Correct |
5 ms |
340 KB |
correct |
38 |
Correct |
99 ms |
1596 KB |
correct |
39 |
Correct |
81 ms |
1492 KB |
correct |
40 |
Correct |
64 ms |
1364 KB |
correct |
41 |
Correct |
89 ms |
1604 KB |
correct |
42 |
Correct |
79 ms |
1612 KB |
correct |
43 |
Correct |
48 ms |
1108 KB |
correct |
44 |
Correct |
38 ms |
852 KB |
correct |
45 |
Correct |
48 ms |
976 KB |
correct |
46 |
Correct |
34 ms |
852 KB |
correct |
47 |
Correct |
15 ms |
596 KB |
correct |
48 |
Correct |
3 ms |
340 KB |
correct |
49 |
Correct |
5 ms |
340 KB |
correct |
50 |
Correct |
15 ms |
592 KB |
correct |
51 |
Correct |
45 ms |
960 KB |
correct |
52 |
Correct |
37 ms |
900 KB |
correct |
53 |
Correct |
33 ms |
724 KB |
correct |
54 |
Correct |
47 ms |
1108 KB |
correct |
55 |
Correct |
49 ms |
980 KB |
correct |
56 |
Correct |
49 ms |
976 KB |
correct |
57 |
Correct |
48 ms |
988 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
212 KB |
correct |
3 |
Incorrect |
77 ms |
4028 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Correct |
1 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
212 KB |
correct |
5 |
Correct |
0 ms |
212 KB |
correct |
6 |
Correct |
0 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
0 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
0 ms |
212 KB |
correct |
13 |
Correct |
0 ms |
212 KB |
correct |
14 |
Correct |
2 ms |
340 KB |
correct |
15 |
Correct |
1 ms |
340 KB |
correct |
16 |
Correct |
1 ms |
340 KB |
correct |
17 |
Correct |
2 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
1 ms |
340 KB |
correct |
20 |
Correct |
1 ms |
328 KB |
correct |
21 |
Correct |
1 ms |
340 KB |
correct |
22 |
Correct |
1 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
360 KB |
correct |
24 |
Correct |
1 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
340 KB |
correct |
26 |
Correct |
1 ms |
340 KB |
correct |
27 |
Correct |
1 ms |
340 KB |
correct |
28 |
Correct |
1 ms |
340 KB |
correct |
29 |
Correct |
0 ms |
340 KB |
correct |
30 |
Correct |
1 ms |
340 KB |
correct |
31 |
Correct |
1 ms |
340 KB |
correct |
32 |
Correct |
1 ms |
340 KB |
correct |
33 |
Correct |
1 ms |
340 KB |
correct |
34 |
Correct |
108 ms |
1628 KB |
correct |
35 |
Correct |
91 ms |
1572 KB |
correct |
36 |
Correct |
65 ms |
1368 KB |
correct |
37 |
Correct |
5 ms |
340 KB |
correct |
38 |
Correct |
99 ms |
1596 KB |
correct |
39 |
Correct |
81 ms |
1492 KB |
correct |
40 |
Correct |
64 ms |
1364 KB |
correct |
41 |
Correct |
89 ms |
1604 KB |
correct |
42 |
Correct |
79 ms |
1612 KB |
correct |
43 |
Correct |
48 ms |
1108 KB |
correct |
44 |
Correct |
38 ms |
852 KB |
correct |
45 |
Correct |
48 ms |
976 KB |
correct |
46 |
Correct |
34 ms |
852 KB |
correct |
47 |
Correct |
15 ms |
596 KB |
correct |
48 |
Correct |
3 ms |
340 KB |
correct |
49 |
Correct |
5 ms |
340 KB |
correct |
50 |
Correct |
15 ms |
592 KB |
correct |
51 |
Correct |
45 ms |
960 KB |
correct |
52 |
Correct |
37 ms |
900 KB |
correct |
53 |
Correct |
33 ms |
724 KB |
correct |
54 |
Correct |
47 ms |
1108 KB |
correct |
55 |
Correct |
49 ms |
980 KB |
correct |
56 |
Correct |
49 ms |
976 KB |
correct |
57 |
Correct |
48 ms |
988 KB |
correct |
58 |
Correct |
0 ms |
212 KB |
correct |
59 |
Correct |
0 ms |
212 KB |
correct |
60 |
Incorrect |
77 ms |
4028 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |