POJ 2472

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#define MAXN 105
#define MAXM 10005
#define MOD 10000
#define inf 1500000000
#define eps 1e-9
#define pi acos(-1.0)
typedef long long LL;
using namespace std;
int n, m, u, v;
double g[MAXN][MAXN], x;
void floyd() {
for (int k = 1; k <= n; k++) 
for (int i = 1; i <= n; i++) 
for (int j = 1; j <= n; j++) 
g[i][j] = max(g[i][j], g[i][k] * g[k][j]);
}
int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
while (scanf("%d", &n) && n) {
scanf("%d", &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j) g[i][j] = 1;
else g[i][j] = 0;
}
}
for (int i = 0; i < m; i++) {
scanf("%d %d %lf", &u, &v, &x);
g[u][v] = g[v][u] = x / 100;
}
floyd();
printf("%.6lf percent\n", g[1][n] * 100);
}
    return 0;
}

posted on 2012-11-28 13:49  Sure_Yi  阅读(108)  评论(0编辑  收藏  举报

导航