-----------------------------------
This question is graph theory shortest path, but we have to change it in some detail
For example, because it is considered the exchange rate, we initialize will be 0
We also altered relaxation operation
-----------------------------------
Also, subject to the exchange rate (and shaping)
So we wanted to change decimals
-----------------------------------
And, the exchange rate is in our operation "loss"
So, we are left with part of the exchange rate is 1- (readily available)
----------------------------------
DOUBLE warning
----------------------------------
These are special attention
In fact, the range of data as well as an array of pits only 100,000 RE
----------------------------------
Topic links : Miku
----------------------------------
#include<iostream> #include<queue> #include<stack> #include<algorithm> #include<cstring> using namespace std; int n,m; struct bian { int to; int next; double v; //注意,是double } b[1000010]; double dis[1000010];//double警告 queue<int> q; int head[1000001]; int pb; void add(int form,int to,double v) {//double警告 pb++; b[pb].to=to; b[pb].v=1-v;//省很多事的 b[pb].next=head[form]; head[form]=pb; } bool vis[1000001]; int main() { memset(dis,0,sizeof(dis)); cin>>n>>m; int x,y,z; for(int i=1; I <= m; ++ I) { CIN >> >> X >> Y Z; the Add (X, Y, ( Double ) Z / 100 ); the Add (Y, X, ( Double ) Z / 100 ); // must be processed into a decimal } CIN >> >> X Y; { // the SPFA portion DIS [X] = . 1 ; VIS [X] = . 1 ; q.push (X); // initialize { the while (Q. size ()) { int U = q.front (); q.pop (); VIS [U] =0; for(int i=head[u]; i; i=b[i].next) { int v=b[i].to; if(dis[v]<dis[u]*b[i].v) {//特殊操作 dis[v]=dis[u]*b[i].v;//特殊操作 { if(!vis[v]) { q.push(v); vis[v]=1; } } } } } } } Double ANS = 100 / DIS [Y]; // Double warning the printf ( " % .8lf " , ANS); // decimal Oh return 0 ; }
------------------------------------
That's all.