#include "simurgh.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
const int N = 3e4 + 2;
int p[N], sz[N], used[N];
vector <int> g[N];
int f_s(int v){
return (p[v] == v)?v:p[v] = f_s(p[v]);
}
void u_s(int a, int b){
a = f_s(a);
b = f_s(b);
if(a != b){
if(sz[a] < sz[b])
swap(a, b);
p[b] = a;
sz[a] += sz[b];
}
}
int tin[N], tout[N], timer;
void dfs(int v, int pr){
tin[v] = ++ timer;
for(int to : g[v]){
if(to == pr)
continue;
dfs(to, v);
}
tout[v] = timer;
}
bool upper(int a, int b){
return tin[a] <= tin[b] && tout[a] >= tout[b];
}
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
vector<int> r(n - 1);
int m = (int)u.size();
for(int i = 0; i < n; i ++)
p[i] = i, sz[i] = 1;
int pt = 0;
for(int i = 0; i < m; i ++){
if(f_s(u[i]) != f_s(v[i])){
r[pt ++] = i;
u_s(u[i], v[i]);
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
}
dfs(0, 0);
for(int i = 0; i < pt; i ++){
vector <int> ind, rs;
int a = u[ r[i] ], b = v[ r[i] ];
if(upper(b, a))
swap(a, b);
for(int j = 0; j < m; j ++){
int cnt = 0;
if(upper(b, u[j]))
cnt ++;
if(upper(b, v[j]))
cnt ++;
if(cnt == 1)
ind.push_back(j);
}
int mx = 0;
for(int j = 0; j < ind.size(); j ++){
int id = ind[j], pre = r[i];
r[i] = id;
int ret = count_common_roads(r);
mx = max(mx, ret);
r[i] = pre;
rs.emplace_back(ret);
}
for(int j = 0; j < rs.size(); j ++){
if(rs[j] == mx){
used[ ind[j] ] = 2;
}
}
}
pt = 0;
for(int i = 0; i < m; i ++){
if(used[i] == 2)
r[pt ++] = i;
}
return r;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:73:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < ind.size(); j ++){
~~^~~~~~~~~~~~
simurgh.cpp:81:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < rs.size(); j ++){
~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1076 KB |
correct |
2 |
Correct |
3 ms |
1216 KB |
correct |
3 |
Correct |
3 ms |
1072 KB |
correct |
4 |
Correct |
3 ms |
1108 KB |
correct |
5 |
Correct |
3 ms |
1076 KB |
correct |
6 |
Correct |
3 ms |
1016 KB |
correct |
7 |
Correct |
3 ms |
1020 KB |
correct |
8 |
Correct |
2 ms |
1016 KB |
correct |
9 |
Correct |
3 ms |
1104 KB |
correct |
10 |
Correct |
2 ms |
1016 KB |
correct |
11 |
Correct |
3 ms |
1076 KB |
correct |
12 |
Correct |
3 ms |
1076 KB |
correct |
13 |
Correct |
3 ms |
1016 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1076 KB |
correct |
2 |
Correct |
3 ms |
1216 KB |
correct |
3 |
Correct |
3 ms |
1072 KB |
correct |
4 |
Correct |
3 ms |
1108 KB |
correct |
5 |
Correct |
3 ms |
1076 KB |
correct |
6 |
Correct |
3 ms |
1016 KB |
correct |
7 |
Correct |
3 ms |
1020 KB |
correct |
8 |
Correct |
2 ms |
1016 KB |
correct |
9 |
Correct |
3 ms |
1104 KB |
correct |
10 |
Correct |
2 ms |
1016 KB |
correct |
11 |
Correct |
3 ms |
1076 KB |
correct |
12 |
Correct |
3 ms |
1076 KB |
correct |
13 |
Correct |
3 ms |
1016 KB |
correct |
14 |
Correct |
15 ms |
1016 KB |
correct |
15 |
Correct |
13 ms |
1016 KB |
correct |
16 |
Correct |
12 ms |
1116 KB |
correct |
17 |
Correct |
11 ms |
1112 KB |
correct |
18 |
Correct |
6 ms |
1112 KB |
correct |
19 |
Correct |
12 ms |
1016 KB |
correct |
20 |
Correct |
13 ms |
1120 KB |
correct |
21 |
Correct |
9 ms |
1016 KB |
correct |
22 |
Correct |
7 ms |
1076 KB |
correct |
23 |
Correct |
7 ms |
1016 KB |
correct |
24 |
Correct |
6 ms |
1076 KB |
correct |
25 |
Correct |
3 ms |
1064 KB |
correct |
26 |
Correct |
7 ms |
1080 KB |
correct |
27 |
Correct |
7 ms |
1016 KB |
correct |
28 |
Correct |
4 ms |
1016 KB |
correct |
29 |
Correct |
3 ms |
1016 KB |
correct |
30 |
Correct |
8 ms |
1116 KB |
correct |
31 |
Correct |
9 ms |
1076 KB |
correct |
32 |
Correct |
9 ms |
1084 KB |
correct |
33 |
Correct |
8 ms |
1016 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1076 KB |
correct |
2 |
Correct |
3 ms |
1216 KB |
correct |
3 |
Correct |
3 ms |
1072 KB |
correct |
4 |
Correct |
3 ms |
1108 KB |
correct |
5 |
Correct |
3 ms |
1076 KB |
correct |
6 |
Correct |
3 ms |
1016 KB |
correct |
7 |
Correct |
3 ms |
1020 KB |
correct |
8 |
Correct |
2 ms |
1016 KB |
correct |
9 |
Correct |
3 ms |
1104 KB |
correct |
10 |
Correct |
2 ms |
1016 KB |
correct |
11 |
Correct |
3 ms |
1076 KB |
correct |
12 |
Correct |
3 ms |
1076 KB |
correct |
13 |
Correct |
3 ms |
1016 KB |
correct |
14 |
Correct |
15 ms |
1016 KB |
correct |
15 |
Correct |
13 ms |
1016 KB |
correct |
16 |
Correct |
12 ms |
1116 KB |
correct |
17 |
Correct |
11 ms |
1112 KB |
correct |
18 |
Correct |
6 ms |
1112 KB |
correct |
19 |
Correct |
12 ms |
1016 KB |
correct |
20 |
Correct |
13 ms |
1120 KB |
correct |
21 |
Correct |
9 ms |
1016 KB |
correct |
22 |
Correct |
7 ms |
1076 KB |
correct |
23 |
Correct |
7 ms |
1016 KB |
correct |
24 |
Correct |
6 ms |
1076 KB |
correct |
25 |
Correct |
3 ms |
1064 KB |
correct |
26 |
Correct |
7 ms |
1080 KB |
correct |
27 |
Correct |
7 ms |
1016 KB |
correct |
28 |
Correct |
4 ms |
1016 KB |
correct |
29 |
Correct |
3 ms |
1016 KB |
correct |
30 |
Correct |
8 ms |
1116 KB |
correct |
31 |
Correct |
9 ms |
1076 KB |
correct |
32 |
Correct |
9 ms |
1084 KB |
correct |
33 |
Correct |
8 ms |
1016 KB |
correct |
34 |
Incorrect |
196 ms |
2012 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1076 KB |
correct |
2 |
Correct |
3 ms |
1016 KB |
correct |
3 |
Incorrect |
155 ms |
3152 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1076 KB |
correct |
2 |
Correct |
3 ms |
1216 KB |
correct |
3 |
Correct |
3 ms |
1072 KB |
correct |
4 |
Correct |
3 ms |
1108 KB |
correct |
5 |
Correct |
3 ms |
1076 KB |
correct |
6 |
Correct |
3 ms |
1016 KB |
correct |
7 |
Correct |
3 ms |
1020 KB |
correct |
8 |
Correct |
2 ms |
1016 KB |
correct |
9 |
Correct |
3 ms |
1104 KB |
correct |
10 |
Correct |
2 ms |
1016 KB |
correct |
11 |
Correct |
3 ms |
1076 KB |
correct |
12 |
Correct |
3 ms |
1076 KB |
correct |
13 |
Correct |
3 ms |
1016 KB |
correct |
14 |
Correct |
15 ms |
1016 KB |
correct |
15 |
Correct |
13 ms |
1016 KB |
correct |
16 |
Correct |
12 ms |
1116 KB |
correct |
17 |
Correct |
11 ms |
1112 KB |
correct |
18 |
Correct |
6 ms |
1112 KB |
correct |
19 |
Correct |
12 ms |
1016 KB |
correct |
20 |
Correct |
13 ms |
1120 KB |
correct |
21 |
Correct |
9 ms |
1016 KB |
correct |
22 |
Correct |
7 ms |
1076 KB |
correct |
23 |
Correct |
7 ms |
1016 KB |
correct |
24 |
Correct |
6 ms |
1076 KB |
correct |
25 |
Correct |
3 ms |
1064 KB |
correct |
26 |
Correct |
7 ms |
1080 KB |
correct |
27 |
Correct |
7 ms |
1016 KB |
correct |
28 |
Correct |
4 ms |
1016 KB |
correct |
29 |
Correct |
3 ms |
1016 KB |
correct |
30 |
Correct |
8 ms |
1116 KB |
correct |
31 |
Correct |
9 ms |
1076 KB |
correct |
32 |
Correct |
9 ms |
1084 KB |
correct |
33 |
Correct |
8 ms |
1016 KB |
correct |
34 |
Incorrect |
196 ms |
2012 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |