Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=3665
Test instructions Analysis: Take 0 as the starting point to find the shortest path of sea. So you can use N as the super Sink point, using Floyd to find the shortest path of 0 to N.
/*Seasidetime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) total submission (s): 1151 ACC epted Submission (s): 839Problem Descriptionxiaoy is living in a big city, there be N towns in it and some towns near the Sea. All these towns is numbered from 0 to N-1 and Xiaoy lives in the town numbered ' 0 '. There is some directed roads connecting them. It is guaranteed so can reach any town from the town numbered ' 0 ', and not all towns connect to each other by roads Directly, and there are no ring in the city. One day, Xiaoy want-to-go to the seaside, he asks-to-help him find-out the the shortest the. Inputthere is several test cases. In each cases the first line contains an integer N (0<=n<=10), indicating the number of the towns. Then followed N blocks of data, in block-i there is the integers, MI (0<=mi<=n-1) and Pi, then MI lines followed. Mi means there is MI roads beginning with the i-th town. Pi indicates whether the i-th town is NEAr to the sea, pi=0 means No, pi=1 means Yes. In next Mi lines, each line contains the integers SMi and LMi, which means that the distance between the i-th town and the SMi town is LMi. Outputeach case takes one line, print the shortest length that xiaoy reach seaside. Sample Input51 1 Sample Output2 Source2010 Asia regional Harbin*///Floyd:d[i][j] = min (D[i][j], d[i][k]+d[k][j])#include <cstdio>#include<iostream>using namespacestd;Const intMAXN = -+Ten;#defineINF 1000001intM[MAXN], P[MAXN], D[MAXN][MAXN];voidinit () { for(inti =0; i < MAXN; i++) for(intj =0; J < Maxn; J + +) if(i = = j) D[i][j] =0; ElseD[I][J] =INF;}intMain () {intN, S, l; while(~SCANF ("%d", &N)) {init (); for(inti =0; I < n; i++) {scanf ("%d%d", &m[i], &P[i]); if(P[i]) d[i][n] =0; for(intj =0; J < m[i];j++) {scanf ("%d%d", &s, &l); D[s][i]= D[i][s] =l; } } for(intK =0; K <= N; k++) for(inti =0; I <= N; i++) for(intj =0; J <= N; J + +) D[i][j]= Min (D[i][j], d[i][k]+D[k][j]); printf ("%d\n", d[0][n]); } return 0;}
HDU 3665 Seaside floyd+ Super Meeting point