#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define SZ(x) int((x).size())
#define X first
#define Y second
#define sep ' '
const ll MAXN = 510; //TODO: fix MAXN
int n , m , common , mark[MAXN] , H[MAXN] , par[MAXN] , ind[MAXN] , tree[MAXN * MAXN] , ans[MAXN * MAXN];
vector<pii> E , adj[MAXN];
int query(int A[]){
vector<int> vec;
for(int i = 0 ; i < m ; i++){
if(A[i]){
vec.push_back(i);
}
}
//assert(SZ(vec) == n - 1);
return count_common_roads(vec);
}
void DFS(int v){
mark[v] = 1;
for(pii i : adj[v]){
int u = i.X , w = i.Y;
if(mark[u]){
continue;
}
//cout << v << sep << u << sep << w << endl;
par[u] = v;
ind[u] = w;
tree[w] = 1;
H[u] = H[v] + 1;
DFS(u);
}
}
void Calc(int v , int u , int index){
int mx = common , W = -1 , x = v;
vector<pii> res;
tree[index] = 1;
while(x != u){
if(ans[ind[x]] != -1){
if(W != -1){
res.push_back({W - ans[ind[x]] , x});
x = par[x];
continue;
}
tree[ind[x]] = 0;
int cur = query(tree);
tree[ind[x]] = 1;
res.push_back({cur , x});
W = cur + ans[ind[x]];
x = par[x];
continue;
}
tree[ind[x]] = 0;
int cur = query(tree);
tree[ind[x]] = 1;
res.push_back({cur , x});
x = par[x];
}
tree[index] = 0;
//cout << "==========" << endl;
//cout << v << sep << u << sep << index << endl;
for(pii i : res){
//cout << i.X << sep << i.Y << endl;
mx = max(mx , i.X);
}
for(pii i : res){
if(i.X == mx){
ans[ind[i.Y]] = 0;
}
else{
ans[ind[i.Y]] = 1;
}
}
if(common == mx){
ans[index] = 0;
}
else{
ans[index] = 1;
}
}
vector<int> find_roads(int N, vector<int> U, vector<int> V) {
fill(ans , ans + MAXN * MAXN , -1);
n = N; m = SZ(U);
for(int i = 0 ; i < m ; i++){
adj[V[i]].push_back({U[i] , i});
adj[U[i]].push_back({V[i] , i});
E.push_back({V[i] , U[i]});
}
DFS(0);
common = query(tree);
for(int i = 0 ; i < m ; i++){
if(H[E[i].X] < H[E[i].Y]){
swap(E[i].X , E[i].Y);
}
}
for(int i = 0 ; i < m ; i++){
if(tree[i] == 0){
Calc(E[i].X , E[i].Y , i);
/*for(int j = 0 ; j < m ; j++){
cout << ans[j] << sep;
}
cout << endl;*/
}
}
for(int i = 0 ; i < m ; i++){
if(ans[i] == -1){
ans[i] = 1;
}
}
vector<int> res;
for(int i = 0 ; i < m ; i++){
if(ans[i]){
res.push_back(i);
}
}
assert(SZ(res) <= n - 1);
return res;
}
# |
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 |
1236 KB |
correct |
5 |
Correct |
1 ms |
1236 KB |
correct |
6 |
Correct |
1 ms |
1236 KB |
correct |
7 |
Correct |
1 ms |
1236 KB |
correct |
8 |
Correct |
1 ms |
1236 KB |
correct |
9 |
Correct |
1 ms |
1236 KB |
correct |
10 |
Correct |
1 ms |
1236 KB |
correct |
11 |
Correct |
1 ms |
1236 KB |
correct |
12 |
Correct |
1 ms |
1236 KB |
correct |
13 |
Correct |
1 ms |
1236 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 |
1236 KB |
correct |
5 |
Correct |
1 ms |
1236 KB |
correct |
6 |
Correct |
1 ms |
1236 KB |
correct |
7 |
Correct |
1 ms |
1236 KB |
correct |
8 |
Correct |
1 ms |
1236 KB |
correct |
9 |
Correct |
1 ms |
1236 KB |
correct |
10 |
Correct |
1 ms |
1236 KB |
correct |
11 |
Correct |
1 ms |
1236 KB |
correct |
12 |
Correct |
1 ms |
1236 KB |
correct |
13 |
Correct |
1 ms |
1236 KB |
correct |
14 |
Correct |
7 ms |
1416 KB |
correct |
15 |
Correct |
7 ms |
1428 KB |
correct |
16 |
Correct |
8 ms |
1424 KB |
correct |
17 |
Correct |
6 ms |
1412 KB |
correct |
18 |
Correct |
2 ms |
1364 KB |
correct |
19 |
Correct |
6 ms |
1424 KB |
correct |
20 |
Correct |
5 ms |
1364 KB |
correct |
21 |
Correct |
5 ms |
1364 KB |
correct |
22 |
Correct |
4 ms |
1344 KB |
correct |
23 |
Correct |
3 ms |
1364 KB |
correct |
24 |
Correct |
3 ms |
1364 KB |
correct |
25 |
Correct |
1 ms |
1236 KB |
correct |
26 |
Correct |
3 ms |
1364 KB |
correct |
27 |
Correct |
4 ms |
1364 KB |
correct |
28 |
Correct |
2 ms |
1364 KB |
correct |
29 |
Correct |
1 ms |
1236 KB |
correct |
30 |
Correct |
3 ms |
1340 KB |
correct |
31 |
Correct |
3 ms |
1364 KB |
correct |
32 |
Correct |
3 ms |
1392 KB |
correct |
33 |
Correct |
4 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 |
1236 KB |
correct |
5 |
Correct |
1 ms |
1236 KB |
correct |
6 |
Correct |
1 ms |
1236 KB |
correct |
7 |
Correct |
1 ms |
1236 KB |
correct |
8 |
Correct |
1 ms |
1236 KB |
correct |
9 |
Correct |
1 ms |
1236 KB |
correct |
10 |
Correct |
1 ms |
1236 KB |
correct |
11 |
Correct |
1 ms |
1236 KB |
correct |
12 |
Correct |
1 ms |
1236 KB |
correct |
13 |
Correct |
1 ms |
1236 KB |
correct |
14 |
Correct |
7 ms |
1416 KB |
correct |
15 |
Correct |
7 ms |
1428 KB |
correct |
16 |
Correct |
8 ms |
1424 KB |
correct |
17 |
Correct |
6 ms |
1412 KB |
correct |
18 |
Correct |
2 ms |
1364 KB |
correct |
19 |
Correct |
6 ms |
1424 KB |
correct |
20 |
Correct |
5 ms |
1364 KB |
correct |
21 |
Correct |
5 ms |
1364 KB |
correct |
22 |
Correct |
4 ms |
1344 KB |
correct |
23 |
Correct |
3 ms |
1364 KB |
correct |
24 |
Correct |
3 ms |
1364 KB |
correct |
25 |
Correct |
1 ms |
1236 KB |
correct |
26 |
Correct |
3 ms |
1364 KB |
correct |
27 |
Correct |
4 ms |
1364 KB |
correct |
28 |
Correct |
2 ms |
1364 KB |
correct |
29 |
Correct |
1 ms |
1236 KB |
correct |
30 |
Correct |
3 ms |
1340 KB |
correct |
31 |
Correct |
3 ms |
1364 KB |
correct |
32 |
Correct |
3 ms |
1392 KB |
correct |
33 |
Correct |
4 ms |
1364 KB |
correct |
34 |
Correct |
2513 ms |
3184 KB |
correct |
35 |
Correct |
2348 ms |
3224 KB |
correct |
36 |
Correct |
1153 ms |
2888 KB |
correct |
37 |
Correct |
14 ms |
1364 KB |
correct |
38 |
Correct |
2484 ms |
2988 KB |
correct |
39 |
Correct |
1855 ms |
2864 KB |
correct |
40 |
Correct |
1224 ms |
2580 KB |
correct |
41 |
Correct |
2625 ms |
2984 KB |
correct |
42 |
Correct |
2680 ms |
2860 KB |
correct |
43 |
Correct |
807 ms |
2360 KB |
correct |
44 |
Correct |
536 ms |
2124 KB |
correct |
45 |
Correct |
702 ms |
2272 KB |
correct |
46 |
Correct |
412 ms |
2036 KB |
correct |
47 |
Correct |
102 ms |
1668 KB |
correct |
48 |
Correct |
3 ms |
1364 KB |
correct |
49 |
Correct |
15 ms |
1452 KB |
correct |
50 |
Correct |
91 ms |
1664 KB |
correct |
51 |
Correct |
668 ms |
2132 KB |
correct |
52 |
Correct |
489 ms |
2092 KB |
correct |
53 |
Correct |
387 ms |
2004 KB |
correct |
54 |
Correct |
742 ms |
2500 KB |
correct |
55 |
Correct |
684 ms |
2304 KB |
correct |
56 |
Correct |
684 ms |
2252 KB |
correct |
57 |
Correct |
668 ms |
2128 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1236 KB |
correct |
2 |
Correct |
1 ms |
1236 KB |
correct |
3 |
Incorrect |
2818 ms |
5344 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 |
1236 KB |
correct |
5 |
Correct |
1 ms |
1236 KB |
correct |
6 |
Correct |
1 ms |
1236 KB |
correct |
7 |
Correct |
1 ms |
1236 KB |
correct |
8 |
Correct |
1 ms |
1236 KB |
correct |
9 |
Correct |
1 ms |
1236 KB |
correct |
10 |
Correct |
1 ms |
1236 KB |
correct |
11 |
Correct |
1 ms |
1236 KB |
correct |
12 |
Correct |
1 ms |
1236 KB |
correct |
13 |
Correct |
1 ms |
1236 KB |
correct |
14 |
Correct |
7 ms |
1416 KB |
correct |
15 |
Correct |
7 ms |
1428 KB |
correct |
16 |
Correct |
8 ms |
1424 KB |
correct |
17 |
Correct |
6 ms |
1412 KB |
correct |
18 |
Correct |
2 ms |
1364 KB |
correct |
19 |
Correct |
6 ms |
1424 KB |
correct |
20 |
Correct |
5 ms |
1364 KB |
correct |
21 |
Correct |
5 ms |
1364 KB |
correct |
22 |
Correct |
4 ms |
1344 KB |
correct |
23 |
Correct |
3 ms |
1364 KB |
correct |
24 |
Correct |
3 ms |
1364 KB |
correct |
25 |
Correct |
1 ms |
1236 KB |
correct |
26 |
Correct |
3 ms |
1364 KB |
correct |
27 |
Correct |
4 ms |
1364 KB |
correct |
28 |
Correct |
2 ms |
1364 KB |
correct |
29 |
Correct |
1 ms |
1236 KB |
correct |
30 |
Correct |
3 ms |
1340 KB |
correct |
31 |
Correct |
3 ms |
1364 KB |
correct |
32 |
Correct |
3 ms |
1392 KB |
correct |
33 |
Correct |
4 ms |
1364 KB |
correct |
34 |
Correct |
2513 ms |
3184 KB |
correct |
35 |
Correct |
2348 ms |
3224 KB |
correct |
36 |
Correct |
1153 ms |
2888 KB |
correct |
37 |
Correct |
14 ms |
1364 KB |
correct |
38 |
Correct |
2484 ms |
2988 KB |
correct |
39 |
Correct |
1855 ms |
2864 KB |
correct |
40 |
Correct |
1224 ms |
2580 KB |
correct |
41 |
Correct |
2625 ms |
2984 KB |
correct |
42 |
Correct |
2680 ms |
2860 KB |
correct |
43 |
Correct |
807 ms |
2360 KB |
correct |
44 |
Correct |
536 ms |
2124 KB |
correct |
45 |
Correct |
702 ms |
2272 KB |
correct |
46 |
Correct |
412 ms |
2036 KB |
correct |
47 |
Correct |
102 ms |
1668 KB |
correct |
48 |
Correct |
3 ms |
1364 KB |
correct |
49 |
Correct |
15 ms |
1452 KB |
correct |
50 |
Correct |
91 ms |
1664 KB |
correct |
51 |
Correct |
668 ms |
2132 KB |
correct |
52 |
Correct |
489 ms |
2092 KB |
correct |
53 |
Correct |
387 ms |
2004 KB |
correct |
54 |
Correct |
742 ms |
2500 KB |
correct |
55 |
Correct |
684 ms |
2304 KB |
correct |
56 |
Correct |
684 ms |
2252 KB |
correct |
57 |
Correct |
668 ms |
2128 KB |
correct |
58 |
Correct |
1 ms |
1236 KB |
correct |
59 |
Correct |
1 ms |
1236 KB |
correct |
60 |
Incorrect |
2818 ms |
5344 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |