You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
const int N = 2010 ;
const int M = 2e5 + 10 ; // 边数
typedef pair < double , int > PDI ;
int n ; // n个节点
int m ; // m条边
double d [ N ] ; // 从A点出发, 到达每个点的最大距离
bool st [ N ] ; // 点i是不是已经出队列
int h [ N ] , e [ M ] , ne [ M ] , idx ;
double w [ M ] ;
void add ( int a , int b , double c ) {
e [ idx ] = b , w [ idx ] = c , ne [ idx ] = h [ a ] , h [ a ] = idx + + ;
}
int s , t ;
void dijkstra ( ) {
priority_queue < PDI > q ; // 大根堆
d [ s ] = 1 ; // 剩余的百分比(想像一下手机电池, 目前是100%状态出发)
q . push ( { 1 , s } ) ; // 大根堆,按距离最大到小排序
while ( q . size ( ) ) {
auto t = q . top ( ) ;
q . pop ( ) ;
int u = t . second ;
if ( st [ u ] ) continue ;
st [ u ] = true ;
for ( int i = h [ u ] ; ~ i ; i = ne [ i ] ) {
int v = e [ i ] ;
double a = 1 - w [ i ] ; // 100%减去消耗率,得到本路径的剩余率,需要与带过的数据连乘
if ( d [ v ] < d [ u ] * a ) { // 利用u更新j的路径最大值
d [ v ] = d [ u ] * a ;
q . push ( { d [ v ] , v } ) ;
}
}
}
}
int main ( ) {
memset ( h , - 1 , sizeof h ) ;
cin > > n > > m ;
while ( m - - ) {
int a , b , c ;
cin > > a > > b > > c ;
double w = c * 0.01 ; // 消耗的百分比,举例:从A->B的消耗百分比为2%
add ( a , b , w ) , add ( b , a , w ) ;
}
cin > > s > > t ;
dijkstra ( ) ;
printf ( " %.8lf \n " , 100 / d [ t ] ) ;
return 0 ;
}