http://acm.hdu.edu.cn/showproblem.php?pid=1217
注意这里不能用Dijkstra,因为乘法中小于1相当于加法中的小于0
#include "stdio.h"
#include "iostream"
#include "string"
#include "map"
using namespace std;
const int maxn = 205;
map<string,int>curr;
string a,b;
int n;
double maps[maxn][maxn];
void Floyd()
{
for( int k=1;k<=n;k++ )
{
for( int i=1;i<=n;i++ )
{
for( int j=1;j<=n;j++ )
{
if( maps[i][j] < maps[i][k] * maps[k][j] )
maps[i][j] = maps[i][k] * maps[k][j];
}
}
}
}
int main()
{
int i,j,m,cas=1;
double rate;
while( scanf("%d",&n)!=EOF ,n)
{
for( i=1;i<=n;i++ )
{
for( j=1;j<=n;j++ )
{
maps[i][j] = 0.0;
}
}
for( i=1; i<=n; i++ )
{
cin>>a;
curr[a]=i;
}
scanf("%d",&m);
for( i=1;i<=m;i++ )
{
cin>>a>>rate>>b;
maps[curr[a]][curr[b]] = rate;
}
Floyd();
if( maps[1][1]>1.0 )
printf("Case %d: Yes\n",cas++);
else
printf("Case %d: No\n",cas++);
}
return 0;
}