HDU 3665 Seaside

Source: Internet
Author: User

Topic Links:

http://acm.split.hdu.edu.cn/showproblem.php?pid=3665

problem DescriptionXiaoy was living in a big city, there was 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 are 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 is takes one line, and the print the shortest length that xiaoy reach seaside.

Sample Input51 01 12 02 33 11 14 1000 10 1

Sample Output2 Hint: Test Instructions:A large town with N small towns, in order of 0 to N-1, give two number A, a, a, say I to other towns have a road, B indicates whether the place has the sea, 0 means there is no sea, 1 means there is sea. Then in the given A1,X;A1 there is a path between the I and the A1, and the distance is X. The smallest distance from 0 to the city with Sea.The following:Simple shortest-circuit problem. Code:
#include <cmath> #include <cstdio> #include <cstring> #include <algorithm>using namespace std; const int MAXN = 10+10; #define MET (b) memset (A,b,sizeof (a)) #define INF 0x3f3f3f3fint Map[maxn][maxn];int VISITED[MAXN]    , Dis[maxn];int num[maxn];int n,m;void Dijkstra (int x) {int min=0,p=0;        for (int i=0;i<n;i++) {dis[i]=map[x][i];    visited[i]=0;    } visited[x]=1;        for (int i=0;i<n;i++) {min=inf; for (int j=0;j<n;j++) {if (!visited[j]&&dis[j]<min) {min                    =DIS[J];                P=j;        }} visited[p]=1; for (int j=0;j<n;j++) {if (!visited[j]&&dis[p]+map[p][j]<dis[j]) dis[j]=dis[        P]+MAP[P][J]; }}}int Main () {while (scanf ("%d", &n)!=eof) {for (Int. i=0;i<n;i++) for (int j=0;j<n;j++        ) Map[i][j]=inf;        Met (num,0); for (int i=0;i<n;i++) {scanf ("%d%d", &m,&num[i]);                for (int j=0;j<m;j++) {int x, y;                scanf ("%d%d", &x,&y);            Map[i][x]=map[x][i]=y;        }} Dijkstra (0);        int ans=inf;        for (int i=0;i<n;i++) {if (num[i]==1) ans=min (Ans,dis[i]);    } printf ("%d\n", ans); }}

  

HDU 3665 Seaside

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.