#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;
int mx = 0;
for (int i = 0; i < m; i++) {
if (comp[u[i]] != comp[v[i]] && flag[i] == 1) {
good = i;
break;
}
}
if (good == -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);
mx = max(mx, cnt.back().first);
res.pop_back();
}
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
1 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
1 ms |
212 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
1 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
1 ms |
212 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
14 |
Correct |
1 ms |
340 KB |
correct |
15 |
Correct |
2 ms |
340 KB |
correct |
16 |
Correct |
1 ms |
340 KB |
correct |
17 |
Correct |
1 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
2 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 |
212 KB |
correct |
30 |
Correct |
1 ms |
340 KB |
correct |
31 |
Correct |
1 ms |
340 KB |
correct |
32 |
Correct |
1 ms |
244 KB |
correct |
33 |
Correct |
1 ms |
340 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
1 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
1 ms |
212 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
14 |
Correct |
1 ms |
340 KB |
correct |
15 |
Correct |
2 ms |
340 KB |
correct |
16 |
Correct |
1 ms |
340 KB |
correct |
17 |
Correct |
1 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
2 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 |
212 KB |
correct |
30 |
Correct |
1 ms |
340 KB |
correct |
31 |
Correct |
1 ms |
340 KB |
correct |
32 |
Correct |
1 ms |
244 KB |
correct |
33 |
Correct |
1 ms |
340 KB |
correct |
34 |
Correct |
96 ms |
1492 KB |
correct |
35 |
Correct |
82 ms |
1776 KB |
correct |
36 |
Correct |
57 ms |
1548 KB |
correct |
37 |
Correct |
6 ms |
340 KB |
correct |
38 |
Correct |
85 ms |
1808 KB |
correct |
39 |
Correct |
73 ms |
1676 KB |
correct |
40 |
Correct |
56 ms |
1540 KB |
correct |
41 |
Correct |
47 ms |
1884 KB |
correct |
42 |
Correct |
76 ms |
1780 KB |
correct |
43 |
Correct |
42 ms |
1236 KB |
correct |
44 |
Correct |
43 ms |
980 KB |
correct |
45 |
Correct |
40 ms |
980 KB |
correct |
46 |
Correct |
31 ms |
848 KB |
correct |
47 |
Correct |
19 ms |
596 KB |
correct |
48 |
Correct |
3 ms |
340 KB |
correct |
49 |
Correct |
6 ms |
420 KB |
correct |
50 |
Correct |
16 ms |
596 KB |
correct |
51 |
Correct |
44 ms |
1060 KB |
correct |
52 |
Correct |
33 ms |
984 KB |
correct |
53 |
Correct |
29 ms |
852 KB |
correct |
54 |
Correct |
48 ms |
1236 KB |
correct |
55 |
Correct |
44 ms |
1068 KB |
correct |
56 |
Correct |
47 ms |
1028 KB |
correct |
57 |
Correct |
40 ms |
1108 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
212 KB |
correct |
3 |
Incorrect |
52 ms |
3896 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
1 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
1 ms |
212 KB |
correct |
9 |
Correct |
1 ms |
212 KB |
correct |
10 |
Correct |
1 ms |
212 KB |
correct |
11 |
Correct |
1 ms |
212 KB |
correct |
12 |
Correct |
1 ms |
212 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
14 |
Correct |
1 ms |
340 KB |
correct |
15 |
Correct |
2 ms |
340 KB |
correct |
16 |
Correct |
1 ms |
340 KB |
correct |
17 |
Correct |
1 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
2 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 |
212 KB |
correct |
30 |
Correct |
1 ms |
340 KB |
correct |
31 |
Correct |
1 ms |
340 KB |
correct |
32 |
Correct |
1 ms |
244 KB |
correct |
33 |
Correct |
1 ms |
340 KB |
correct |
34 |
Correct |
96 ms |
1492 KB |
correct |
35 |
Correct |
82 ms |
1776 KB |
correct |
36 |
Correct |
57 ms |
1548 KB |
correct |
37 |
Correct |
6 ms |
340 KB |
correct |
38 |
Correct |
85 ms |
1808 KB |
correct |
39 |
Correct |
73 ms |
1676 KB |
correct |
40 |
Correct |
56 ms |
1540 KB |
correct |
41 |
Correct |
47 ms |
1884 KB |
correct |
42 |
Correct |
76 ms |
1780 KB |
correct |
43 |
Correct |
42 ms |
1236 KB |
correct |
44 |
Correct |
43 ms |
980 KB |
correct |
45 |
Correct |
40 ms |
980 KB |
correct |
46 |
Correct |
31 ms |
848 KB |
correct |
47 |
Correct |
19 ms |
596 KB |
correct |
48 |
Correct |
3 ms |
340 KB |
correct |
49 |
Correct |
6 ms |
420 KB |
correct |
50 |
Correct |
16 ms |
596 KB |
correct |
51 |
Correct |
44 ms |
1060 KB |
correct |
52 |
Correct |
33 ms |
984 KB |
correct |
53 |
Correct |
29 ms |
852 KB |
correct |
54 |
Correct |
48 ms |
1236 KB |
correct |
55 |
Correct |
44 ms |
1068 KB |
correct |
56 |
Correct |
47 ms |
1028 KB |
correct |
57 |
Correct |
40 ms |
1108 KB |
correct |
58 |
Correct |
0 ms |
212 KB |
correct |
59 |
Correct |
0 ms |
212 KB |
correct |
60 |
Incorrect |
52 ms |
3896 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |