#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef complex<ld> point;
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cerr << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 500 + 10;
int n, m, h[maxn], par[maxn], dsu[maxn*maxn], edge[maxn*maxn][2];
vector<int> g[maxn], t[maxn];
vector<int> badedge;
vector<int> ans;
bool vis[maxn], mark[maxn];
int getpar(int v){
//debug(v, dsu[v]);
return (dsu[v] == -1? v: dsu[v] = getpar(dsu[v]));
}
void merge(int u, int v){
//debug("merge", u, v);
if ((u = getpar(u)) == (v = getpar(v))) return;
//debug(u, v);
if (u < v) swap(u, v);
dsu[v] = u;
}
void predfs(int v){
vis[v] = true;
for (auto x: g[v]){
int u = edge[x][0] ^ edge[x][1] ^ v;
if (!vis[u]){
t[v].push_back(x);
t[u].push_back(x);
ans.push_back(x);
// debug("add", x);
h[u] = h[v] + 1;
predfs(u);
}
else if (h[u] > h[v]){
badedge.push_back(x);
}
}
}
void dfs(int v, int p = -1){
//debug(v, p, h[v]);
par[v] = p;
for (auto x: t[v]){
//debug(x);
if (x == p) continue;
int u = edge[x][0] ^ edge[x][1] ^ v;
//debug(edge[x][0], edge[x][1], u);
h[u] = h[v] + 1;
dfs(u, x);
}
}
std::vector<int> find_roads(int _n, std::vector<int> u, std::vector<int> v) {
memset(dsu, -1, sizeof dsu);
n = _n;
m = u.size();
for (int i = 0; i < m; i++){
edge[i][0] = u[i];
edge[i][1] = v[i];
g[v[i]].push_back(i);
g[u[i]].push_back(i);
}
predfs(0);
//debug(ans.size(), badedge.size());
int res = count_common_roads(ans);
//debug(res);
//assert(ans.size() == n-1);
for (auto x: badedge){
//debug(x);
//assert(getpar(m) != getpar(m+1));
dfs(0);
int v = edge[x][0], u = edge[x][1];
if (h[v] < h[u]) swap(u, v);
// debug(v, u);
while(v != u && getpar(x) != m+1){
int e = par[v];
if (getpar(e) == m+1 && getpar(x) == m){
ans.erase(find(all(ans), e));
t[edge[e][0]].erase(find(all(t[edge[e][0]]), e));
t[edge[e][1]].erase(find(all(t[edge[e][1]]), e));
res++;
break;
}
// debug(e, x);
if (getpar(e) != getpar(x)){
// debug(0);
ans.erase(find(all(ans), e));
ans.push_back(x);
int tmp = count_common_roads(ans);
ans.pop_back();
ans.push_back(e);
if (tmp == res){
// debug(1);
merge(e, x);
}
else if (tmp < res){
// debug(2);
merge(e, m);
merge(x, m+1);
}
else{
// debug(3);
// debug("readd", e, x);
res = tmp;
merge(e, m+1);
ans.pop_back();
t[edge[e][0]].erase(find(all(t[edge[e][0]]), e));
t[edge[e][1]].erase(find(all(t[edge[e][1]]), e));
merge(x, m);
break;
}
}
v = edge[e][0] ^ edge[e][1] ^ v;
}
// debug(x, getpar(x));
if (getpar(x) == getpar(m)){
ans.push_back(x);
t[edge[x][0]].push_back(x);
t[edge[x][1]].push_back(x);
}
else{
merge(x, m+1);
}
}
//for (auto x: ans) debug(x);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1236 KB |
correct |
2 |
Correct |
1 ms |
1236 KB |
correct |
3 |
Correct |
1 ms |
1236 KB |
correct |
4 |
Correct |
1 ms |
1364 KB |
correct |
5 |
Correct |
1 ms |
1364 KB |
correct |
6 |
Correct |
1 ms |
1360 KB |
correct |
7 |
Correct |
1 ms |
1360 KB |
correct |
8 |
Correct |
1 ms |
1364 KB |
correct |
9 |
Correct |
1 ms |
1236 KB |
correct |
10 |
Correct |
1 ms |
1364 KB |
correct |
11 |
Correct |
1 ms |
1364 KB |
correct |
12 |
Correct |
1 ms |
1356 KB |
correct |
13 |
Correct |
1 ms |
1364 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1236 KB |
correct |
2 |
Correct |
1 ms |
1236 KB |
correct |
3 |
Correct |
1 ms |
1236 KB |
correct |
4 |
Correct |
1 ms |
1364 KB |
correct |
5 |
Correct |
1 ms |
1364 KB |
correct |
6 |
Correct |
1 ms |
1360 KB |
correct |
7 |
Correct |
1 ms |
1360 KB |
correct |
8 |
Correct |
1 ms |
1364 KB |
correct |
9 |
Correct |
1 ms |
1236 KB |
correct |
10 |
Correct |
1 ms |
1364 KB |
correct |
11 |
Correct |
1 ms |
1364 KB |
correct |
12 |
Correct |
1 ms |
1356 KB |
correct |
13 |
Correct |
1 ms |
1364 KB |
correct |
14 |
Correct |
2 ms |
1364 KB |
correct |
15 |
Correct |
2 ms |
1364 KB |
correct |
16 |
Correct |
2 ms |
1364 KB |
correct |
17 |
Correct |
2 ms |
1364 KB |
correct |
18 |
Correct |
1 ms |
1360 KB |
correct |
19 |
Correct |
2 ms |
1364 KB |
correct |
20 |
Correct |
2 ms |
1364 KB |
correct |
21 |
Correct |
2 ms |
1364 KB |
correct |
22 |
Correct |
2 ms |
1364 KB |
correct |
23 |
Correct |
1 ms |
1356 KB |
correct |
24 |
Correct |
2 ms |
1364 KB |
correct |
25 |
Correct |
1 ms |
1368 KB |
correct |
26 |
Correct |
1 ms |
1356 KB |
correct |
27 |
Correct |
2 ms |
1364 KB |
correct |
28 |
Correct |
1 ms |
1364 KB |
correct |
29 |
Correct |
1 ms |
1364 KB |
correct |
30 |
Correct |
2 ms |
1364 KB |
correct |
31 |
Correct |
2 ms |
1360 KB |
correct |
32 |
Correct |
2 ms |
1364 KB |
correct |
33 |
Correct |
1 ms |
1364 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1236 KB |
correct |
2 |
Correct |
1 ms |
1236 KB |
correct |
3 |
Correct |
1 ms |
1236 KB |
correct |
4 |
Correct |
1 ms |
1364 KB |
correct |
5 |
Correct |
1 ms |
1364 KB |
correct |
6 |
Correct |
1 ms |
1360 KB |
correct |
7 |
Correct |
1 ms |
1360 KB |
correct |
8 |
Correct |
1 ms |
1364 KB |
correct |
9 |
Correct |
1 ms |
1236 KB |
correct |
10 |
Correct |
1 ms |
1364 KB |
correct |
11 |
Correct |
1 ms |
1364 KB |
correct |
12 |
Correct |
1 ms |
1356 KB |
correct |
13 |
Correct |
1 ms |
1364 KB |
correct |
14 |
Correct |
2 ms |
1364 KB |
correct |
15 |
Correct |
2 ms |
1364 KB |
correct |
16 |
Correct |
2 ms |
1364 KB |
correct |
17 |
Correct |
2 ms |
1364 KB |
correct |
18 |
Correct |
1 ms |
1360 KB |
correct |
19 |
Correct |
2 ms |
1364 KB |
correct |
20 |
Correct |
2 ms |
1364 KB |
correct |
21 |
Correct |
2 ms |
1364 KB |
correct |
22 |
Correct |
2 ms |
1364 KB |
correct |
23 |
Correct |
1 ms |
1356 KB |
correct |
24 |
Correct |
2 ms |
1364 KB |
correct |
25 |
Correct |
1 ms |
1368 KB |
correct |
26 |
Correct |
1 ms |
1356 KB |
correct |
27 |
Correct |
2 ms |
1364 KB |
correct |
28 |
Correct |
1 ms |
1364 KB |
correct |
29 |
Correct |
1 ms |
1364 KB |
correct |
30 |
Correct |
2 ms |
1364 KB |
correct |
31 |
Correct |
2 ms |
1360 KB |
correct |
32 |
Correct |
2 ms |
1364 KB |
correct |
33 |
Correct |
1 ms |
1364 KB |
correct |
34 |
Correct |
150 ms |
2780 KB |
correct |
35 |
Correct |
143 ms |
2740 KB |
correct |
36 |
Correct |
96 ms |
2388 KB |
correct |
37 |
Correct |
6 ms |
1452 KB |
correct |
38 |
Correct |
159 ms |
2764 KB |
correct |
39 |
Correct |
126 ms |
2644 KB |
correct |
40 |
Correct |
91 ms |
2388 KB |
correct |
41 |
Correct |
128 ms |
2776 KB |
correct |
42 |
Correct |
137 ms |
2780 KB |
correct |
43 |
Correct |
70 ms |
2192 KB |
correct |
44 |
Correct |
57 ms |
1984 KB |
correct |
45 |
Correct |
84 ms |
2060 KB |
correct |
46 |
Correct |
51 ms |
1932 KB |
correct |
47 |
Correct |
22 ms |
1616 KB |
correct |
48 |
Correct |
2 ms |
1320 KB |
correct |
49 |
Correct |
7 ms |
1364 KB |
correct |
50 |
Correct |
23 ms |
1656 KB |
correct |
51 |
Correct |
69 ms |
2132 KB |
correct |
52 |
Correct |
58 ms |
1884 KB |
correct |
53 |
Correct |
51 ms |
1936 KB |
correct |
54 |
Correct |
72 ms |
2192 KB |
correct |
55 |
Correct |
67 ms |
2004 KB |
correct |
56 |
Correct |
70 ms |
2076 KB |
correct |
57 |
Correct |
73 ms |
2080 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1236 KB |
correct |
2 |
Correct |
1 ms |
1364 KB |
correct |
3 |
Incorrect |
114 ms |
4800 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1236 KB |
correct |
2 |
Correct |
1 ms |
1236 KB |
correct |
3 |
Correct |
1 ms |
1236 KB |
correct |
4 |
Correct |
1 ms |
1364 KB |
correct |
5 |
Correct |
1 ms |
1364 KB |
correct |
6 |
Correct |
1 ms |
1360 KB |
correct |
7 |
Correct |
1 ms |
1360 KB |
correct |
8 |
Correct |
1 ms |
1364 KB |
correct |
9 |
Correct |
1 ms |
1236 KB |
correct |
10 |
Correct |
1 ms |
1364 KB |
correct |
11 |
Correct |
1 ms |
1364 KB |
correct |
12 |
Correct |
1 ms |
1356 KB |
correct |
13 |
Correct |
1 ms |
1364 KB |
correct |
14 |
Correct |
2 ms |
1364 KB |
correct |
15 |
Correct |
2 ms |
1364 KB |
correct |
16 |
Correct |
2 ms |
1364 KB |
correct |
17 |
Correct |
2 ms |
1364 KB |
correct |
18 |
Correct |
1 ms |
1360 KB |
correct |
19 |
Correct |
2 ms |
1364 KB |
correct |
20 |
Correct |
2 ms |
1364 KB |
correct |
21 |
Correct |
2 ms |
1364 KB |
correct |
22 |
Correct |
2 ms |
1364 KB |
correct |
23 |
Correct |
1 ms |
1356 KB |
correct |
24 |
Correct |
2 ms |
1364 KB |
correct |
25 |
Correct |
1 ms |
1368 KB |
correct |
26 |
Correct |
1 ms |
1356 KB |
correct |
27 |
Correct |
2 ms |
1364 KB |
correct |
28 |
Correct |
1 ms |
1364 KB |
correct |
29 |
Correct |
1 ms |
1364 KB |
correct |
30 |
Correct |
2 ms |
1364 KB |
correct |
31 |
Correct |
2 ms |
1360 KB |
correct |
32 |
Correct |
2 ms |
1364 KB |
correct |
33 |
Correct |
1 ms |
1364 KB |
correct |
34 |
Correct |
150 ms |
2780 KB |
correct |
35 |
Correct |
143 ms |
2740 KB |
correct |
36 |
Correct |
96 ms |
2388 KB |
correct |
37 |
Correct |
6 ms |
1452 KB |
correct |
38 |
Correct |
159 ms |
2764 KB |
correct |
39 |
Correct |
126 ms |
2644 KB |
correct |
40 |
Correct |
91 ms |
2388 KB |
correct |
41 |
Correct |
128 ms |
2776 KB |
correct |
42 |
Correct |
137 ms |
2780 KB |
correct |
43 |
Correct |
70 ms |
2192 KB |
correct |
44 |
Correct |
57 ms |
1984 KB |
correct |
45 |
Correct |
84 ms |
2060 KB |
correct |
46 |
Correct |
51 ms |
1932 KB |
correct |
47 |
Correct |
22 ms |
1616 KB |
correct |
48 |
Correct |
2 ms |
1320 KB |
correct |
49 |
Correct |
7 ms |
1364 KB |
correct |
50 |
Correct |
23 ms |
1656 KB |
correct |
51 |
Correct |
69 ms |
2132 KB |
correct |
52 |
Correct |
58 ms |
1884 KB |
correct |
53 |
Correct |
51 ms |
1936 KB |
correct |
54 |
Correct |
72 ms |
2192 KB |
correct |
55 |
Correct |
67 ms |
2004 KB |
correct |
56 |
Correct |
70 ms |
2076 KB |
correct |
57 |
Correct |
73 ms |
2080 KB |
correct |
58 |
Correct |
1 ms |
1236 KB |
correct |
59 |
Correct |
1 ms |
1364 KB |
correct |
60 |
Incorrect |
114 ms |
4800 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |