#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int> > g[512];
int par[512];
int pare[512];
vector<int> cycle;
void dfs(int u, int p = -1){
for(auto v : g[u]){
if(v.first == p) continue;
if(par[v.first] != -1){
// Cycle is found!
if(cycle.empty()){
// First cycle found. Use it.
int x = u;
cycle.push_back(v.second);
while(x != v.first){
cycle.push_back(pare[x]);
x = par[x];
}
}
}else{
pare[v.first] = v.second;
par[v.first] = u;
dfs(v.first, u);
}
}
}
bool disabled[512*256];
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
int m = u.size();
do{
for(int i = 0; i < n; i++){
g[i].clear();
}
for(int i = 0; i < m; i++){
if(!disabled[i]) {
g[u[i]].emplace_back(v[i], i);
g[v[i]].emplace_back(u[i], i);
}
}
memset(par, -1, sizeof(par));
memset(pare, 0, sizeof(pare));
cycle.clear();
par[0] = -2;
dfs(0);
vector<int> r;
for(int i = 1; i < n; i++){
r.push_back(pare[i]);
}
int ret = count_common_roads(r);
if(ret == n-1) return r;
int mx = -1;
int mindex = -1;
if(ret > mx){
mx = ret;
mindex = 0;
}
for(int i = 1; i < cycle.size(); i++){
r.erase(find(r.begin(), r.end(), cycle[i]));
r.push_back(cycle[i-1]);
ret = count_common_roads(r);
if(ret == n-1) return r;
if(ret > mx){
mx = ret;
mindex = i;
}
}
disabled[cycle[mindex]] = true;
}while(!cycle.empty());
vector<int> r;
for(int i = 1; i < n; i++){
r.push_back(pare[i]);
}
return r;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:59:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < cycle.size(); i++){
~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
correct |
2 |
Correct |
2 ms |
384 KB |
correct |
3 |
Correct |
2 ms |
384 KB |
correct |
4 |
Correct |
2 ms |
384 KB |
correct |
5 |
Correct |
2 ms |
356 KB |
correct |
6 |
Correct |
2 ms |
384 KB |
correct |
7 |
Correct |
2 ms |
472 KB |
correct |
8 |
Correct |
2 ms |
384 KB |
correct |
9 |
Correct |
2 ms |
384 KB |
correct |
10 |
Correct |
2 ms |
384 KB |
correct |
11 |
Correct |
2 ms |
384 KB |
correct |
12 |
Correct |
2 ms |
384 KB |
correct |
13 |
Correct |
3 ms |
384 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
correct |
2 |
Correct |
2 ms |
384 KB |
correct |
3 |
Correct |
2 ms |
384 KB |
correct |
4 |
Correct |
2 ms |
384 KB |
correct |
5 |
Correct |
2 ms |
356 KB |
correct |
6 |
Correct |
2 ms |
384 KB |
correct |
7 |
Correct |
2 ms |
472 KB |
correct |
8 |
Correct |
2 ms |
384 KB |
correct |
9 |
Correct |
2 ms |
384 KB |
correct |
10 |
Correct |
2 ms |
384 KB |
correct |
11 |
Correct |
2 ms |
384 KB |
correct |
12 |
Correct |
2 ms |
384 KB |
correct |
13 |
Correct |
3 ms |
384 KB |
correct |
14 |
Correct |
22 ms |
384 KB |
correct |
15 |
Correct |
21 ms |
444 KB |
correct |
16 |
Correct |
21 ms |
384 KB |
correct |
17 |
Correct |
17 ms |
436 KB |
correct |
18 |
Correct |
7 ms |
356 KB |
correct |
19 |
Correct |
19 ms |
384 KB |
correct |
20 |
Correct |
19 ms |
432 KB |
correct |
21 |
Correct |
21 ms |
436 KB |
correct |
22 |
Correct |
10 ms |
384 KB |
correct |
23 |
Correct |
8 ms |
384 KB |
correct |
24 |
Correct |
8 ms |
384 KB |
correct |
25 |
Correct |
2 ms |
384 KB |
correct |
26 |
Correct |
7 ms |
384 KB |
correct |
27 |
Correct |
8 ms |
420 KB |
correct |
28 |
Correct |
4 ms |
384 KB |
correct |
29 |
Correct |
2 ms |
384 KB |
correct |
30 |
Correct |
11 ms |
384 KB |
correct |
31 |
Correct |
10 ms |
384 KB |
correct |
32 |
Correct |
10 ms |
356 KB |
correct |
33 |
Correct |
10 ms |
384 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
correct |
2 |
Correct |
2 ms |
384 KB |
correct |
3 |
Correct |
2 ms |
384 KB |
correct |
4 |
Correct |
2 ms |
384 KB |
correct |
5 |
Correct |
2 ms |
356 KB |
correct |
6 |
Correct |
2 ms |
384 KB |
correct |
7 |
Correct |
2 ms |
472 KB |
correct |
8 |
Correct |
2 ms |
384 KB |
correct |
9 |
Correct |
2 ms |
384 KB |
correct |
10 |
Correct |
2 ms |
384 KB |
correct |
11 |
Correct |
2 ms |
384 KB |
correct |
12 |
Correct |
2 ms |
384 KB |
correct |
13 |
Correct |
3 ms |
384 KB |
correct |
14 |
Correct |
22 ms |
384 KB |
correct |
15 |
Correct |
21 ms |
444 KB |
correct |
16 |
Correct |
21 ms |
384 KB |
correct |
17 |
Correct |
17 ms |
436 KB |
correct |
18 |
Correct |
7 ms |
356 KB |
correct |
19 |
Correct |
19 ms |
384 KB |
correct |
20 |
Correct |
19 ms |
432 KB |
correct |
21 |
Correct |
21 ms |
436 KB |
correct |
22 |
Correct |
10 ms |
384 KB |
correct |
23 |
Correct |
8 ms |
384 KB |
correct |
24 |
Correct |
8 ms |
384 KB |
correct |
25 |
Correct |
2 ms |
384 KB |
correct |
26 |
Correct |
7 ms |
384 KB |
correct |
27 |
Correct |
8 ms |
420 KB |
correct |
28 |
Correct |
4 ms |
384 KB |
correct |
29 |
Correct |
2 ms |
384 KB |
correct |
30 |
Correct |
11 ms |
384 KB |
correct |
31 |
Correct |
10 ms |
384 KB |
correct |
32 |
Correct |
10 ms |
356 KB |
correct |
33 |
Correct |
10 ms |
384 KB |
correct |
34 |
Incorrect |
211 ms |
1536 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
correct |
2 |
Correct |
2 ms |
384 KB |
correct |
3 |
Incorrect |
219 ms |
4028 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
correct |
2 |
Correct |
2 ms |
384 KB |
correct |
3 |
Correct |
2 ms |
384 KB |
correct |
4 |
Correct |
2 ms |
384 KB |
correct |
5 |
Correct |
2 ms |
356 KB |
correct |
6 |
Correct |
2 ms |
384 KB |
correct |
7 |
Correct |
2 ms |
472 KB |
correct |
8 |
Correct |
2 ms |
384 KB |
correct |
9 |
Correct |
2 ms |
384 KB |
correct |
10 |
Correct |
2 ms |
384 KB |
correct |
11 |
Correct |
2 ms |
384 KB |
correct |
12 |
Correct |
2 ms |
384 KB |
correct |
13 |
Correct |
3 ms |
384 KB |
correct |
14 |
Correct |
22 ms |
384 KB |
correct |
15 |
Correct |
21 ms |
444 KB |
correct |
16 |
Correct |
21 ms |
384 KB |
correct |
17 |
Correct |
17 ms |
436 KB |
correct |
18 |
Correct |
7 ms |
356 KB |
correct |
19 |
Correct |
19 ms |
384 KB |
correct |
20 |
Correct |
19 ms |
432 KB |
correct |
21 |
Correct |
21 ms |
436 KB |
correct |
22 |
Correct |
10 ms |
384 KB |
correct |
23 |
Correct |
8 ms |
384 KB |
correct |
24 |
Correct |
8 ms |
384 KB |
correct |
25 |
Correct |
2 ms |
384 KB |
correct |
26 |
Correct |
7 ms |
384 KB |
correct |
27 |
Correct |
8 ms |
420 KB |
correct |
28 |
Correct |
4 ms |
384 KB |
correct |
29 |
Correct |
2 ms |
384 KB |
correct |
30 |
Correct |
11 ms |
384 KB |
correct |
31 |
Correct |
10 ms |
384 KB |
correct |
32 |
Correct |
10 ms |
356 KB |
correct |
33 |
Correct |
10 ms |
384 KB |
correct |
34 |
Incorrect |
211 ms |
1536 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |