#include "simurgh.h"
#ifndef EVAL
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
const int N = 5003;
vector <vector <pii>> graph(N), mutable_graph(N);
vector <int> edges, s, cycle;
map <pii, int> id;
bool used[N], used_edges[N*4];
void _initial(int v){
used[v] = 1;
for(auto to : graph[v]){
if(used[to.first]) continue;
edges.pb(to.second);
_initial(to.first);
}
}
void dfs(int v, int p = -1){
used[v] = 1;
s.pb(v);
for(auto to : mutable_graph[v]){
if(p == to.first) continue;
if(used[to.first] == 1){
int flag = 0;
for(auto to2 : s){
if(to2 == to.first) flag++;
if(flag) cycle.pb(to2);
}
}
else if(!used[to.first]){
dfs(to.first, v);
}
}
used[v] = 2;
s.pop_back();
}
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
if(n > 240) exit(0);
vector <int> ans;
for(int i = 0; i < sz(u); i++){
graph[u[i]].pb(mp(v[i], i));
graph[v[i]].pb(mp(u[i], i));
id[mp(min(u[i], v[i]), max(u[i], v[i]))] = i;
}
_initial(0);
for(int i = 0; i < n; i++) used[i] = 0;
int mx = count_common_roads(edges);
ans = edges;
for(auto to : ans) used_edges[to] = 1;
for(int i = 0; i < sz(u); i++){
if(used_edges[i]) continue;
vector <int> cycle_num;
for(auto to : edges){
mutable_graph[u[to]].pb(mp(v[to], to));
mutable_graph[v[to]].pb(mp(u[to], to));
}
mutable_graph[u[i]].pb(mp(v[i], i));
mutable_graph[v[i]].pb(mp(u[i], i));
dfs(u[i]);
for(int j = 0; j < sz(cycle); j++){
if((cycle[j] == u[i] && cycle[(j+1)%sz(cycle)] == v[i]) || (cycle[j] == v[i] && cycle[(j+1)%sz(cycle)] == u[i]))
continue;
cycle_num.pb(id[mp(min(cycle[j], cycle[(j+1)%sz(cycle)]), max(cycle[j], cycle[(j+1)%sz(cycle)]))]);
}
sort(all(cycle_num));
// for(auto to : cycle) cout << to << ' ';
// cout << endl;
set <int> tmp;
for(auto to : edges) tmp.insert(to);
tmp.insert(i);
for(auto to : cycle_num){
tmp.erase(tmp.find(to));
vector <int> g;
for(auto to : tmp) g.pb(to);
auto p = count_common_roads(g);
if(p > mx){
mx = p;
edges = g;
break;
}
tmp.insert(to);
used_edges[to] = 1;
}
cycle.clear();
cycle_num.clear();
for(int j = 0; j < n; j++) mutable_graph[j].clear();
for(int j = 0; j < n; j++) used[j] = 0;
}
return edges;
}
/*
7 21
2 0
0 1
5 2
2 6
1 3
3 0
6 0
4 5
3 2
4 0
1 4
0 5
4 3
4 6
6 1
2 1
5 3
2 4
5 6
5 1
6 3
7 10 9 13 12 17
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
620 KB |
correct |
2 |
Correct |
1 ms |
620 KB |
correct |
3 |
Correct |
1 ms |
620 KB |
correct |
4 |
Correct |
1 ms |
620 KB |
correct |
5 |
Correct |
1 ms |
620 KB |
correct |
6 |
Correct |
1 ms |
620 KB |
correct |
7 |
Correct |
1 ms |
620 KB |
correct |
8 |
Correct |
1 ms |
620 KB |
correct |
9 |
Correct |
1 ms |
620 KB |
correct |
10 |
Correct |
1 ms |
640 KB |
correct |
11 |
Correct |
1 ms |
620 KB |
correct |
12 |
Correct |
1 ms |
640 KB |
correct |
13 |
Correct |
1 ms |
620 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
620 KB |
correct |
2 |
Correct |
1 ms |
620 KB |
correct |
3 |
Correct |
1 ms |
620 KB |
correct |
4 |
Correct |
1 ms |
620 KB |
correct |
5 |
Correct |
1 ms |
620 KB |
correct |
6 |
Correct |
1 ms |
620 KB |
correct |
7 |
Correct |
1 ms |
620 KB |
correct |
8 |
Correct |
1 ms |
620 KB |
correct |
9 |
Correct |
1 ms |
620 KB |
correct |
10 |
Correct |
1 ms |
640 KB |
correct |
11 |
Correct |
1 ms |
620 KB |
correct |
12 |
Correct |
1 ms |
640 KB |
correct |
13 |
Correct |
1 ms |
620 KB |
correct |
14 |
Correct |
27 ms |
748 KB |
correct |
15 |
Correct |
17 ms |
748 KB |
correct |
16 |
Correct |
24 ms |
748 KB |
correct |
17 |
Correct |
23 ms |
640 KB |
correct |
18 |
Correct |
9 ms |
748 KB |
correct |
19 |
Correct |
27 ms |
748 KB |
correct |
20 |
Correct |
18 ms |
620 KB |
correct |
21 |
Correct |
20 ms |
620 KB |
correct |
22 |
Correct |
12 ms |
620 KB |
correct |
23 |
Correct |
12 ms |
620 KB |
correct |
24 |
Correct |
14 ms |
620 KB |
correct |
25 |
Correct |
1 ms |
620 KB |
correct |
26 |
Correct |
10 ms |
620 KB |
correct |
27 |
Correct |
12 ms |
620 KB |
correct |
28 |
Correct |
4 ms |
620 KB |
correct |
29 |
Correct |
2 ms |
620 KB |
correct |
30 |
Correct |
14 ms |
748 KB |
correct |
31 |
Correct |
14 ms |
748 KB |
correct |
32 |
Correct |
15 ms |
620 KB |
correct |
33 |
Correct |
13 ms |
620 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
620 KB |
correct |
2 |
Correct |
1 ms |
620 KB |
correct |
3 |
Correct |
1 ms |
620 KB |
correct |
4 |
Correct |
1 ms |
620 KB |
correct |
5 |
Correct |
1 ms |
620 KB |
correct |
6 |
Correct |
1 ms |
620 KB |
correct |
7 |
Correct |
1 ms |
620 KB |
correct |
8 |
Correct |
1 ms |
620 KB |
correct |
9 |
Correct |
1 ms |
620 KB |
correct |
10 |
Correct |
1 ms |
640 KB |
correct |
11 |
Correct |
1 ms |
620 KB |
correct |
12 |
Correct |
1 ms |
640 KB |
correct |
13 |
Correct |
1 ms |
620 KB |
correct |
14 |
Correct |
27 ms |
748 KB |
correct |
15 |
Correct |
17 ms |
748 KB |
correct |
16 |
Correct |
24 ms |
748 KB |
correct |
17 |
Correct |
23 ms |
640 KB |
correct |
18 |
Correct |
9 ms |
748 KB |
correct |
19 |
Correct |
27 ms |
748 KB |
correct |
20 |
Correct |
18 ms |
620 KB |
correct |
21 |
Correct |
20 ms |
620 KB |
correct |
22 |
Correct |
12 ms |
620 KB |
correct |
23 |
Correct |
12 ms |
620 KB |
correct |
24 |
Correct |
14 ms |
620 KB |
correct |
25 |
Correct |
1 ms |
620 KB |
correct |
26 |
Correct |
10 ms |
620 KB |
correct |
27 |
Correct |
12 ms |
620 KB |
correct |
28 |
Correct |
4 ms |
620 KB |
correct |
29 |
Correct |
2 ms |
620 KB |
correct |
30 |
Correct |
14 ms |
748 KB |
correct |
31 |
Correct |
14 ms |
748 KB |
correct |
32 |
Correct |
15 ms |
620 KB |
correct |
33 |
Correct |
13 ms |
620 KB |
correct |
34 |
Incorrect |
290 ms |
3596 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
620 KB |
correct |
2 |
Correct |
1 ms |
620 KB |
correct |
3 |
Incorrect |
19 ms |
2412 KB |
Security Violation! Don't try to hack |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
620 KB |
correct |
2 |
Correct |
1 ms |
620 KB |
correct |
3 |
Correct |
1 ms |
620 KB |
correct |
4 |
Correct |
1 ms |
620 KB |
correct |
5 |
Correct |
1 ms |
620 KB |
correct |
6 |
Correct |
1 ms |
620 KB |
correct |
7 |
Correct |
1 ms |
620 KB |
correct |
8 |
Correct |
1 ms |
620 KB |
correct |
9 |
Correct |
1 ms |
620 KB |
correct |
10 |
Correct |
1 ms |
640 KB |
correct |
11 |
Correct |
1 ms |
620 KB |
correct |
12 |
Correct |
1 ms |
640 KB |
correct |
13 |
Correct |
1 ms |
620 KB |
correct |
14 |
Correct |
27 ms |
748 KB |
correct |
15 |
Correct |
17 ms |
748 KB |
correct |
16 |
Correct |
24 ms |
748 KB |
correct |
17 |
Correct |
23 ms |
640 KB |
correct |
18 |
Correct |
9 ms |
748 KB |
correct |
19 |
Correct |
27 ms |
748 KB |
correct |
20 |
Correct |
18 ms |
620 KB |
correct |
21 |
Correct |
20 ms |
620 KB |
correct |
22 |
Correct |
12 ms |
620 KB |
correct |
23 |
Correct |
12 ms |
620 KB |
correct |
24 |
Correct |
14 ms |
620 KB |
correct |
25 |
Correct |
1 ms |
620 KB |
correct |
26 |
Correct |
10 ms |
620 KB |
correct |
27 |
Correct |
12 ms |
620 KB |
correct |
28 |
Correct |
4 ms |
620 KB |
correct |
29 |
Correct |
2 ms |
620 KB |
correct |
30 |
Correct |
14 ms |
748 KB |
correct |
31 |
Correct |
14 ms |
748 KB |
correct |
32 |
Correct |
15 ms |
620 KB |
correct |
33 |
Correct |
13 ms |
620 KB |
correct |
34 |
Incorrect |
290 ms |
3596 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |