Unblocked Project Continuation time limit:3000/1000ms (Java/other) Memory limit:32768/32768k (Java/other) total submission (s): Accepted s Ubmission (s): 10Problem description A province has finally built many roads since it has implemented many years of smooth engineering projects. But the road is not good, every time from one town to another town, there are many ways to choose, and some programmes are more than others to walk the distance is much shorter. This makes pedestrians very troubled.
Now that you know the starting and ending points, you can figure out how much distance you need to walk from the start to the end.
Input This topic contains multiple sets of data, please process to the end of the file. The first row of each group of data contains two positive integers n and M (0<n<200,0<m<1000), representing the number of existing towns and the number of roads that have been built. The towns were numbered 0~n-1. The next line has two integer s,t (0<= "S,t<n) representing the starting and ending points, respectively.
Output for each set of data, in a row, the shortest distance to walk. If there is no route from S to T, then output-1.
Sample INPUT3 30 1 10 2 31 2 10 23 10 1 11 2
Sample output2-1
Authorlinle
Source2008 Zhejiang University Postgraduate second-round warm-up (2)--Full true simulation
#include <stdio.h>#include<string.h>#include<algorithm>#defineINF 0x3f3f3fusing namespacestd;intn,m;intmap[101][101];intMain () { while(~SCANF ("%d%d",&n,&M)) { for(intI=0; i<n;i++) { for(intj=0; j<n;j++) { if(i==j) Map[i][j] =0; ElseMAP[I][J] =INF; } } intA,b,c; for(intI=0; i<m;i++) {scanf ("%d%d%d",&a,&b,&c); MAP[A][B]= min (map[a][b],c);//This step is important .Map[b][a] = min (map[a][b],c);//to consider a point coverage problem } ints,e; scanf ("%d%d",&s,&e); for(intk=0; k<n;k++) for(intI=0; i<n;i++) for(intj=0; j<n;j++) {Map[i][j]= Min (map[i][j],map[i][k]+Map[k][j]); } if(map[s][e]!=INF) printf ("%d\n", Map[s][e]); Elseprintf ("-1\n"); } return 0;}
Continue to smooth the project-floyd