hdu 1224 Free DIY Tour Flyod

来源:互联网 发布:七天网络微信怎么查分 编辑:程序博客网 时间:2024/05/16 17:52

Another Problem be solved by Flyod.Flyod is so powerful.

The portal:http://acm.hdu.edu.cn/showproblem.php?pid=1224

#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAXN 105const int INF = 0x3f3f3f3f;int cost[MAXN][MAXN];int route[MAXN][MAXN];int power[MAXN];void Input(){int T,n,t=0;scanf("%d",&T);while(T--){scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",power+i);}for(int i=1;i<=n+1;i++){for(int j=1;j<=n+1;j++){cost[i][j] = INF;}}for(int i=1;i<=n+1;i++){for(int j=1;j<=n+1;j++){route[i][j] = j;}}int m;scanf("%d",&m);for(int i=0;i<m;i++){int tempa,tempb;scanf("%d %d",&tempa,&tempb);cost[tempa][tempb] = 0;}for(int k=1;k<=n+1;k++){for(int i=1;i<=n+1;i++){for(int j=1;j<=n+1;j++){if(cost[i][k]==INF||cost[k][j]==INF)continue;int temp = cost[i][k] + cost[k][j] +power[k] ;if(cost[i][j]==INF||temp > cost[i][j]){cost[i][j] = temp;route[i][j] = route[i][k];}}}}if(t++)puts("");printf("CASE %d#\n",t);printf("points : %d\n",cost[1][n+1]);printf("circuit : ");int t = 1;printf("1");t = route[t][n+1];while(t!=n+1){printf("->%d",t);t = route[t][n+1];}printf("->%d",1);puts("");}}int main(){//freopen("1224.in","r",stdin);Input();return 0;}


0 0
原创粉丝点击