C++
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int robota,robotb, N;
const int MAX_N = 100010;
vector<pair<int, int>> info[MAX_N];
/*
int a[100]={1, 2,3, 4};
struct Pos
{
int x, y;
double f;
};
Pos pos = { 2, 3, 4.5};
*/
vector<int> path;
int find_path ( int r, int d_sum, int d_max, int prev_r )
{
if( r == robotb )
{
int result=d_sum-d_max;
printf("%d", result);
return 1;
}
for( size_t i = 0; i < info[r].size(); ++i )
{
int adj_r = info[r][i].first;
if ( adj_r == prev_r )
continue;
path.push_back( adj_r );
int d_max2 = max ( d_max, info[r][i].second );
if( find_path( adj_r, d_sum + info[r][i].second, d_max2, r ) )
{
return 1;
}
path.pop_back();
}
return 0;
}
int main()
{
scanf("%d %d %d",&N,&robota,&robotb);
int r1, r2, dist;
for( int i = 0; i < N - 1; ++i )
{
scanf("%d %d %d", &r1, &r2, &dist);
info[r1].push_back ( { r2, dist } );
info[r2].push_back ( { r1, dist } );
}
path.push_back(robota);
find_path ( robota, 0, 0, 0 );
return 0;
}
댓글 0
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
|---|---|---|---|---|
| 공지 | 안내사항 | 관리자 | 2019.12.21 | 173 |
| 74 | 9663 | 관리자 | 2019.12.21 | 124 |
| 73 | 9345 | 관리자 | 2020.04.11 | 160 |
| 72 | 9019 | 관리자 | 2019.12.21 | 126 |
| 71 | 7569 | 관리자 | 2019.12.21 | 123 |
| 70 | 6987 | 관리자 | 2019.12.21 | 125 |
| 69 | 5842 | 관리자 | 2020.04.11 | 161 |
| 68 | 5625 | 관리자 | 2019.12.21 | 119 |
| 67 | 5419 | 관리자 | 2020.04.11 | 166 |
| 66 | 3392 | 관리자 | 2020.04.11 | 166 |
| 65 | 3019 | 관리자 | 2019.12.21 | 121 |
| 64 | 2933 | 관리자 | 2019.12.21 | 123 |
| 63 | 2931 | 관리자 | 2019.12.21 | 121 |
| 62 | 2836 | 관리자 | 2019.12.21 | 120 |
| 61 | 2667 | 관리자 | 2019.12.21 | 123 |
| 60 | 2636 | 관리자 | 2019.12.21 | 123 |
| 59 | 2629 | 관리자 | 2020.04.11 | 156 |
| 58 | 2615 | 관리자 | 2019.12.21 | 121 |
| 57 | 2610 | 관리자 | 2020.04.11 | 158 |
| 56 | 2606 | 관리자 | 2019.12.21 | 121 |
| 55 | 2585 | 관리자 | 2019.12.21 | 127 |
| 54 | 2578 | 관리자 | 2019.12.21 | 121 |
| 53 | 2573 | 관리자 | 2020.04.11 | 161 |
| 52 | 2557 | 관리자 | 2019.12.21 | 121 |
| 51 | 2512 | 관리자 | 2019.12.21 | 121 |
| 50 | 2504 | 관리자 | 2020.04.11 | 157 |
| 49 | 2481 | 관리자 | 2019.12.21 | 122 |
| 48 | 2478 | 관리자 | 2020.04.11 | 158 |
| 47 | 2473 | 관리자 | 2020.04.11 | 163 |
| 46 | 2470 | 관리자 | 2020.04.11 | 161 |