#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);
}
}
}
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);
}
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 i = 0; i < m; i++) {
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 |
0 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
212 KB |
correct |
3 |
Correct |
0 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 |
1 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 |
1 ms |
212 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
212 KB |
correct |
3 |
Correct |
0 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 |
1 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 |
1 ms |
212 KB |
correct |
14 |
Correct |
1 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 |
340 KB |
correct |
21 |
Correct |
1 ms |
340 KB |
correct |
22 |
Correct |
1 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
340 KB |
correct |
24 |
Correct |
1 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
212 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 |
1 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 |
0 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
212 KB |
correct |
3 |
Correct |
0 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 |
1 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 |
1 ms |
212 KB |
correct |
14 |
Correct |
1 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 |
340 KB |
correct |
21 |
Correct |
1 ms |
340 KB |
correct |
22 |
Correct |
1 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
340 KB |
correct |
24 |
Correct |
1 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
212 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 |
1 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 |
98 ms |
1492 KB |
correct |
35 |
Correct |
88 ms |
1484 KB |
correct |
36 |
Correct |
60 ms |
1292 KB |
correct |
37 |
Correct |
5 ms |
340 KB |
correct |
38 |
Correct |
91 ms |
1488 KB |
correct |
39 |
Correct |
76 ms |
1404 KB |
correct |
40 |
Correct |
58 ms |
1304 KB |
correct |
41 |
Correct |
69 ms |
1492 KB |
correct |
42 |
Correct |
68 ms |
1436 KB |
correct |
43 |
Correct |
14 ms |
1076 KB |
correct |
44 |
Correct |
10 ms |
860 KB |
correct |
45 |
Correct |
11 ms |
852 KB |
correct |
46 |
Correct |
9 ms |
724 KB |
correct |
47 |
Correct |
5 ms |
468 KB |
correct |
48 |
Correct |
2 ms |
340 KB |
correct |
49 |
Correct |
3 ms |
340 KB |
correct |
50 |
Correct |
5 ms |
468 KB |
correct |
51 |
Correct |
14 ms |
852 KB |
correct |
52 |
Correct |
9 ms |
848 KB |
correct |
53 |
Correct |
8 ms |
724 KB |
correct |
54 |
Correct |
18 ms |
1120 KB |
correct |
55 |
Correct |
11 ms |
852 KB |
correct |
56 |
Correct |
11 ms |
852 KB |
correct |
57 |
Correct |
11 ms |
924 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
212 KB |
correct |
3 |
Incorrect |
71 ms |
3784 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
212 KB |
correct |
3 |
Correct |
0 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 |
1 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 |
1 ms |
212 KB |
correct |
14 |
Correct |
1 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 |
340 KB |
correct |
21 |
Correct |
1 ms |
340 KB |
correct |
22 |
Correct |
1 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
340 KB |
correct |
24 |
Correct |
1 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
212 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 |
1 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 |
98 ms |
1492 KB |
correct |
35 |
Correct |
88 ms |
1484 KB |
correct |
36 |
Correct |
60 ms |
1292 KB |
correct |
37 |
Correct |
5 ms |
340 KB |
correct |
38 |
Correct |
91 ms |
1488 KB |
correct |
39 |
Correct |
76 ms |
1404 KB |
correct |
40 |
Correct |
58 ms |
1304 KB |
correct |
41 |
Correct |
69 ms |
1492 KB |
correct |
42 |
Correct |
68 ms |
1436 KB |
correct |
43 |
Correct |
14 ms |
1076 KB |
correct |
44 |
Correct |
10 ms |
860 KB |
correct |
45 |
Correct |
11 ms |
852 KB |
correct |
46 |
Correct |
9 ms |
724 KB |
correct |
47 |
Correct |
5 ms |
468 KB |
correct |
48 |
Correct |
2 ms |
340 KB |
correct |
49 |
Correct |
3 ms |
340 KB |
correct |
50 |
Correct |
5 ms |
468 KB |
correct |
51 |
Correct |
14 ms |
852 KB |
correct |
52 |
Correct |
9 ms |
848 KB |
correct |
53 |
Correct |
8 ms |
724 KB |
correct |
54 |
Correct |
18 ms |
1120 KB |
correct |
55 |
Correct |
11 ms |
852 KB |
correct |
56 |
Correct |
11 ms |
852 KB |
correct |
57 |
Correct |
11 ms |
924 KB |
correct |
58 |
Correct |
0 ms |
212 KB |
correct |
59 |
Correct |
0 ms |
212 KB |
correct |
60 |
Incorrect |
71 ms |
3784 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |