include iostream include cmath include string include iomanip include

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include<iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include <stack>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int h[100005] = {0};
pair<int,double> prob[100005];
vector<vector<pair<int, double> > > graph;
int maxSize = 0;
void bfs(int start, int stop)
{
queue< pair<int,int> > que;
que.push(make_pair(0, start));
h[start] = -1;
prob[start] = make_pair(0, 0);
while(que.empty() == false)
{
int currIsland = que.front().second;
double currProbl = prob[currIsland].second;
int len = -que.front().first;
que.pop();
// if(len > prob[currIsland].first)
// continue;
for(int i = 0; i < graph[currIsland].size(); ++i)
{
int nextIsland = graph[currIsland][i].first;
double transProb = graph[currIsland][i].second;
double nextProb;
if(currIsland != start)
nextProb = 1 - (1 - transProb) * ( 1 - currProbl);
else
nextProb = transProb;
if(len + 1 < prob[nextIsland].first)
{
prob[nextIsland] = make_pair(len + 1, nextProb);
h[nextIsland] = currIsland;
que.push(make_pair(-len - 1, nextIsland));
}
else
if(len + 1 == prob[nextIsland].first && nextProb < prob[nextIsland].second)
{
prob[nextIsland] = make_pair(len + 1, nextProb);
h[nextIsland] = currIsland;
que.push(make_pair(-len - 1, nextIsland));
}
// maxSize = max((int)maxSize, (int)que.size());
}
}
}
int main()
{
for(int i = 0; i < 100005; ++i)
{
prob[i] = make_pair(1000000, 5);
}
// freopen("input.txt", "r", stdin);
int n, m;
cin >> n >> m;
int start, stop;
cin >> start >> stop;
start--;
stop--;
graph.resize(n);
for(int i = 0; i < m; ++i)
{
int a,b;
double pr;
cin >> a >> b >> pr;
pr = pr / 100;
a--;
b--;
graph[a].push_back(make_pair(b, pr));
graph[b].push_back(make_pair(a, pr));
}
bfs(start, stop);
int way = stop;
vector<int> wayVec;
while(way != -1)
{
wayVec.push_back(way);
if(way == start)
break;
way = h[way];
}
// cout << maxSize << endl;
cout << fixed << setprecision(9);
cout << wayVec.size() << " " <<prob[stop].second << endl;
while(wayVec.empty() == false)
{
cout << wayVec.back() + 1<< " ";
wayVec.pop_back();
}
return 0;
}