// M
#include<bits/stdc++.h>
#include "simurgh.h"
using namespace std;
const int N = 245, MXM = N * N / 2;
int n, m, A[MXM], B[MXM];
bool Del[MXM], Sure[MXM], MR[N];
char M[N];
int P[N], PE[N];
vector < int > Tre, Cyc;
vector < pair < int , int > > Adj[N];
void DFS(int v, int p, int pe)
{
M[v] = 1;
P[v] = p;
PE[v] = pe;
/*for (auto e : Adj[v])
{
int u = e.first;
int id = e.second;
if (id == pe || Del[id])
continue;
if (Sure[id] && !M[u])
DFS(u, v, id);
}*/
for (auto e : Adj[v])
{
int u = e.first;
int id = e.second;
if (id == pe)
continue;
//if (Sure[id])
//continue;
if (!M[u])
DFS(u, v, id);
else if (M[u] == 1 && !Cyc.size())
{
int nw = v;
while (nw != u)
{
if (!Sure[PE[nw]])
Cyc.push_back(PE[nw]);
else
Tre.push_back(PE[nw]);
MR[nw] = 1;
nw = P[nw];
}
if (!Sure[id])
Cyc.push_back(id);
else
Tre.push_back(id);
}
}
if (pe != -1 && !MR[v])
Tre.push_back(pe);
M[v] = 2;
}
vector < int > find_roads(int _n, vector < int > _u, vector < int > _v)
{
n = _n;
m = (int)_u.size();
for (int i = 0; i < m; i ++)
A[i] = _u[i], B[i] = _v[i];
for (int i = 0; i < m; i ++)
{
Adj[A[i]].push_back({B[i], i});
Adj[B[i]].push_back({A[i], i});
}
assert(m <= 3e4);
int sre = 0;
while (true)
{
Tre.clear();
Cyc.clear();
memset(M, 0, sizeof(M));
memset(MR, 0, sizeof(MR));
DFS(0, -1, -1);
if (!Cyc.size())
break;
vector < int > Val(n + 1, -1);
int mx = -1, mn = n;
for (int i = 0; i < (int)Cyc.size(); i ++)
{
vector < int > tmp = Tre;
for (int j = 0; j < (int)Cyc.size(); j ++)
if (i != j)
tmp.push_back(Cyc[j]);
assert(tmp.size() == n - 1);
Val[i] = count_common_roads(tmp);
/*printf("Asking :: %d || ", Val[i]);
for (int j : tmp)
printf("%d ", j);
printf("\n");*/
mn = min(mn, Val[i]);
mx = max(mx, Val[i]);
}
for (int i = 0; i < (int)Cyc.size(); i ++)
if (Val[i] == mx)
{
int e = Cyc[i];
for (int j = 0; j < Adj[A[e]].size(); j ++)
if (Adj[A[e]][j].second == e)
Adj[A[e]].erase(Adj[A[e]].begin() + j);
for (int j = 0; j < Adj[B[e]].size(); j ++)
if (Adj[B[e]][j].second == e)
Adj[B[e]].erase(Adj[B[e]].begin() + j);
Del[e] = 1;
}
if (mn < mx)
{
for (int i = 0; i < (int)Cyc.size(); i ++)
if (Val[i] == mn && !Sure[Cyc[i]])
Sure[Cyc[i]] = 1, sre ++;
}
if (sre == n - 1)
{
vector < int > vec;
for (int i = 0; i < m; i ++)
if (Sure[i])
vec.push_back(i);
return vec;
}
}
vector < int > vec;
for (int i = 0; i < m; i ++)
if (Del[i] == 0)
vec.push_back(i);
assert(vec.size() == n - 1);
return vec;
}
Compilation message
In file included from /usr/include/c++/9/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
from simurgh.cpp:2:
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:91:43: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
91 | assert(tmp.size() == n - 1);
| ~~~~~~~~~~~^~~~~~~~
simurgh.cpp:106:51: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for (int j = 0; j < Adj[A[e]].size(); j ++)
| ~~^~~~~~~~~~~~~~~~~~
simurgh.cpp:109:51: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | for (int j = 0; j < Adj[B[e]].size(); j ++)
| ~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/9/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
from simurgh.cpp:2:
simurgh.cpp:133:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
133 | assert(vec.size() == n - 1);
| ~~~~~~~~~~~^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
14 |
Correct |
5 ms |
384 KB |
correct |
15 |
Correct |
7 ms |
384 KB |
correct |
16 |
Correct |
6 ms |
384 KB |
correct |
17 |
Correct |
4 ms |
384 KB |
correct |
18 |
Correct |
2 ms |
384 KB |
correct |
19 |
Correct |
4 ms |
384 KB |
correct |
20 |
Correct |
4 ms |
384 KB |
correct |
21 |
Correct |
4 ms |
384 KB |
correct |
22 |
Correct |
3 ms |
384 KB |
correct |
23 |
Correct |
3 ms |
384 KB |
correct |
24 |
Correct |
3 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
2 ms |
384 KB |
correct |
27 |
Correct |
3 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
3 ms |
384 KB |
correct |
31 |
Correct |
3 ms |
384 KB |
correct |
32 |
Correct |
2 ms |
384 KB |
correct |
33 |
Correct |
3 ms |
384 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
14 |
Correct |
5 ms |
384 KB |
correct |
15 |
Correct |
7 ms |
384 KB |
correct |
16 |
Correct |
6 ms |
384 KB |
correct |
17 |
Correct |
4 ms |
384 KB |
correct |
18 |
Correct |
2 ms |
384 KB |
correct |
19 |
Correct |
4 ms |
384 KB |
correct |
20 |
Correct |
4 ms |
384 KB |
correct |
21 |
Correct |
4 ms |
384 KB |
correct |
22 |
Correct |
3 ms |
384 KB |
correct |
23 |
Correct |
3 ms |
384 KB |
correct |
24 |
Correct |
3 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
2 ms |
384 KB |
correct |
27 |
Correct |
3 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
3 ms |
384 KB |
correct |
31 |
Correct |
3 ms |
384 KB |
correct |
32 |
Correct |
2 ms |
384 KB |
correct |
33 |
Correct |
3 ms |
384 KB |
correct |
34 |
Correct |
734 ms |
1912 KB |
correct |
35 |
Correct |
626 ms |
1656 KB |
correct |
36 |
Correct |
349 ms |
1656 KB |
correct |
37 |
Correct |
10 ms |
384 KB |
correct |
38 |
Correct |
712 ms |
1784 KB |
correct |
39 |
Correct |
606 ms |
1532 KB |
correct |
40 |
Correct |
406 ms |
1400 KB |
correct |
41 |
Correct |
1758 ms |
2040 KB |
correct |
42 |
Correct |
1723 ms |
1896 KB |
correct |
43 |
Correct |
526 ms |
1400 KB |
correct |
44 |
Correct |
404 ms |
896 KB |
correct |
45 |
Correct |
526 ms |
1148 KB |
correct |
46 |
Correct |
337 ms |
1016 KB |
correct |
47 |
Correct |
94 ms |
760 KB |
correct |
48 |
Correct |
4 ms |
384 KB |
correct |
49 |
Correct |
15 ms |
384 KB |
correct |
50 |
Correct |
92 ms |
760 KB |
correct |
51 |
Correct |
499 ms |
1144 KB |
correct |
52 |
Correct |
394 ms |
1144 KB |
correct |
53 |
Correct |
380 ms |
904 KB |
correct |
54 |
Correct |
613 ms |
1220 KB |
correct |
55 |
Correct |
374 ms |
1144 KB |
correct |
56 |
Correct |
364 ms |
1156 KB |
correct |
57 |
Correct |
387 ms |
1024 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Correct |
1 ms |
384 KB |
correct |
3 |
Runtime error |
24 ms |
3456 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
1 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
14 |
Correct |
5 ms |
384 KB |
correct |
15 |
Correct |
7 ms |
384 KB |
correct |
16 |
Correct |
6 ms |
384 KB |
correct |
17 |
Correct |
4 ms |
384 KB |
correct |
18 |
Correct |
2 ms |
384 KB |
correct |
19 |
Correct |
4 ms |
384 KB |
correct |
20 |
Correct |
4 ms |
384 KB |
correct |
21 |
Correct |
4 ms |
384 KB |
correct |
22 |
Correct |
3 ms |
384 KB |
correct |
23 |
Correct |
3 ms |
384 KB |
correct |
24 |
Correct |
3 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
2 ms |
384 KB |
correct |
27 |
Correct |
3 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
3 ms |
384 KB |
correct |
31 |
Correct |
3 ms |
384 KB |
correct |
32 |
Correct |
2 ms |
384 KB |
correct |
33 |
Correct |
3 ms |
384 KB |
correct |
34 |
Correct |
734 ms |
1912 KB |
correct |
35 |
Correct |
626 ms |
1656 KB |
correct |
36 |
Correct |
349 ms |
1656 KB |
correct |
37 |
Correct |
10 ms |
384 KB |
correct |
38 |
Correct |
712 ms |
1784 KB |
correct |
39 |
Correct |
606 ms |
1532 KB |
correct |
40 |
Correct |
406 ms |
1400 KB |
correct |
41 |
Correct |
1758 ms |
2040 KB |
correct |
42 |
Correct |
1723 ms |
1896 KB |
correct |
43 |
Correct |
526 ms |
1400 KB |
correct |
44 |
Correct |
404 ms |
896 KB |
correct |
45 |
Correct |
526 ms |
1148 KB |
correct |
46 |
Correct |
337 ms |
1016 KB |
correct |
47 |
Correct |
94 ms |
760 KB |
correct |
48 |
Correct |
4 ms |
384 KB |
correct |
49 |
Correct |
15 ms |
384 KB |
correct |
50 |
Correct |
92 ms |
760 KB |
correct |
51 |
Correct |
499 ms |
1144 KB |
correct |
52 |
Correct |
394 ms |
1144 KB |
correct |
53 |
Correct |
380 ms |
904 KB |
correct |
54 |
Correct |
613 ms |
1220 KB |
correct |
55 |
Correct |
374 ms |
1144 KB |
correct |
56 |
Correct |
364 ms |
1156 KB |
correct |
57 |
Correct |
387 ms |
1024 KB |
correct |
58 |
Correct |
0 ms |
384 KB |
correct |
59 |
Correct |
1 ms |
384 KB |
correct |
60 |
Runtime error |
24 ms |
3456 KB |
Execution killed with signal 11 |
61 |
Halted |
0 ms |
0 KB |
- |