Be Attention ,These is may be a locality has more than one broken-car .Clearly,Floyd is simple than Dijkstra in this problem.
The portal:http://acm.hdu.edu.cn/showproblem.php?pid=2923
/**************************************
>File Name :2923.cpp
>Author : nmfloat
>Mail : nmfloat@foxmail.com
>Create Time : 2015年05月15日 星期五 12时15分28秒
**************************************/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
map<string,int>mp;
#define MAXN 1005
int cost[MAXN][MAXN];
const int INF = 0x3f3f3f3f;
char str[1005][15];
int get_num(char * a1){
int i = 0,ans = 0;
while(a1[i]<'0'||a1[i]>'9'){i++;continue;}
while(a1[i]>='0'&&a1[i]<='9'){
ans = ans * 10 + a1[i] - '0';
i++;
}
return ans;
}
int Solve(int n,int m){
int ans = 0;
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(cost[i][k]+cost[k][j]<cost[i][j]){
cost[i][j] = cost[i][k] + cost[k][j];
}
}
}
}
for(int i=0;i<m;i++){
string temp = str[i];
int tempk = mp[temp];
ans += cost[tempk][1] + cost[1][tempk];
}
return ans;
}
void Input(){
int n,m,c,k,ld,t=1,cst;
char tempa[15],tempb[15],tempc[25];
while(scanf("%d %d %d",&n,&m,&c),n+m+c){
mp.clear();k=1;
string temp,temp1,temp2;
scanf("%s",tempa);
temp = tempa;
mp[temp] = k++;
for(int i=0;i<m;i++){
scanf("%s",str[i]);
//temp = tempa;
// if(!mp[temp]){
// mp[temp] = k++;
//}
}
ld = k;
memset(cost,0x3f,sizeof(cost));
for(int i=0;i<c;i++){
scanf("%s %s %s",tempa,tempc,tempb);
temp1 = tempa;temp2 = tempb;
if(!mp[temp1]){mp[temp1] = k++;}
if(!mp[temp2]){mp[temp2] = k++;}
int lenc = strlen(tempc);
cst = get_num(tempc);
int k1 = mp[temp1];
int k2 = mp[temp2];
if(tempc[0]=='<'&&cost[k2][k1]>cst)cost[k2][k1] = cst;
if(tempc[lenc-1]=='>'&&cost[k1][k2]>cst)cost[k1][k2] = cst;
}
int ans = Solve(n,m);
printf("%d. %d\n",t++,ans);
}
}
int main(void){
freopen("2923.in","r",stdin);
Input();
return 0;
}