#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
// #define int long long
typedef long long ll ;
const ll ooo = 1e14 ;
const ll oo = 2e9 ;
const double PI = acos(-1) ;
const ll M = 1e9 + 7 ;
const int N = 10000010 ;
vector<pair<int , int>> g[501];
vector<int> r , ans , p(501) , dp(501 , 0);
int sz = 0 ;
map<pair<int,int> , int>mp , roy;
int root[501];
ll find(int u){
if(root[u] == u)
return u ;
return root[u] = find(root[u]);
}
void dfs(int u){
if(p[u] + 1)dp[u] = dp[p[u]] + 1;
for(auto v : g[u])
if(v.first != p[u]){
mp[{u , v.first}] = r.size();
mp[{v.first , u}] = r.size();
p[v.first] = u;
r.push_back(v.second);
dfs(v.first);
}
}
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
for(int i = 0 ; i < n ; ++i) root[i] = i ;
sz = n;
int m = u.size();
for(int i = 0 ; i < m ; ++i){
if(find(u[i]) != find(v[i])){
root[find(v[i])] = find(u[i]);
g[u[i]].push_back({v[i] , i});
g[v[i]].push_back({u[i] , i});
}
mp[{u[i] , v[i]}] = -1;
mp[{v[i] , u[i]}] = -1;
}
dp[0] = 0;
dfs(0);
int common = count_common_roads(r);
while(1)count_common_roads(r);
// for(int i = 0 ; i < m && common != n - 1; ++i){
// if(mp[{u[i] , v[i]}] != -1) continue ;
// if(dp[u[i]] > dp[v[i]]) swap(u[i] , v[i]);
// int x = u[i] , y = v[i];
// vector<int> r2 ;
// int mx = common ;
// while(dp[y]){
// vector<int> r1 = r ;
// if(dp[y] == dp[x]){
// if(x == y) break;
// if(!roy[{x , p[x]}]){
// r1[mp[{x , p[x]}]] = i;
// int z = count_common_roads(r1);
// if(z < common) roy[{x , p[x]}] = 1,roy[{p[x] , x}] = 1;
// if(mx < z){
// mx = z;
// r2 = r1;
// }
// }
// x = p[x];
// }else if(dp[y] > dp[x]){
// if(!roy[{y , p[y]}]){
// r1[mp[{y , p[y]}]] = i;
// int z = count_common_roads(r1);
// if(z < common) roy[{y , p[y]}] = 1,roy[{p[y] , y}] = 1;
// if(mx < z){
// mx = z;
// r2 = r1;
// }
// }
// y = p[y];
// }else break;
// }
// if(mx > common){
// roy[{u[i] , v[i]}] = 1;
// roy[{v[i] , u[i]}] = 1;
// for(int i = 0 ; i < n; ++i) g[i].clear() , p[i] = 0;
// for(auto x: r2){
// g[u[x]].push_back({v[x] , x});
// g[v[x]].push_back({u[x] , x});
// }
// r.clear();
// dp[0] = 0;
// dfs(0);
// common = mx ;
// }
// }
return r;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:54:6: warning: unused variable 'common' [-Wunused-variable]
54 | int common = count_common_roads(r);
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |