Topic Links:
http://poj.org/problem?id=1502
Main topic:
There is an information delivery system that contains n processors that transmit information in the same way that the processor with the first number 1 has information that he can pass to the next processor, and that the two processors that have the information can be passed down to the other two processors at the same time, and the four processors that have the information are then delivered in turn, What is the minimum time that all processors receive information?
Problem Solving Ideas:
The transmission path to draw out, see can be converted to the shortest path from 1 to other locations in the longest path, just see the topic feel no idea, but the establishment of the model after the use of Dijkstra is good!
1#include <vector>2#include <queue>3#include <cstdio>4#include <cstring>5#include <cstdlib>6#include <iostream>7#include <algorithm>8 using namespacestd;9 Ten #defineMAXN 110 One #defineINF 0x3f3f3f3f A - intMAP[MAXN][MAXN], DIST[MAXN], N; - the voidinit (); - voidDijkstra (); - - intMain () + { - while(SCANF ("%d", &n)! =EOF) + { A Chars[ -]; at init (); - for(intI=1; i<=n; i++) - for(intj=1; j<i; J + +) - { -scanf ("%s", s); - if(s[0] <='9'&& s[0] >='0') in { -MAP[I][J] =0; to for(intk=0; S[K]; k++) +MAP[I][J] = map[i][j] *Ten+ S[k]-'0'; -Map[j][i] = Map[i][j];//the path is bidirectional the } * } $ Dijkstra ();Panax Notoginseng intMini =0; - for(intI=2; i<=n; i++) theMini =Max (Mini, Dist[i]); +printf ("%d\n", mini); A } the return 0; + } - $ voidInit () $ { - intI, J; - for(i=0; i<maxn; i++) the for(j=0; j<maxn; J + +) - if(i = =j)WuyiMAP[I][J] =0;//the cost of getting to itself is zero the Else -MAP[I][J] =INF; Wu } - About voidDijkstra () $ { - BOOLVIS[MAXN]; -memset (Vis,false,sizeof(Vis)); - for(intI=1; i<=n; i++) ADist[i] = map[1][i]; + thevis[1] =true; - $ for(intI=1; i<n; i++) the { the inttemp =INF, index; the for(intj=2; j<=n; J + +) the { - if(!vis[j] && temp >Dist[j]) in { theindex =J; thetemp =Dist[j]; About } the } the theVis[index] =true; + - for(intj=2; j<=n; J + +) the if(!Vis[j])BayiDist[j] = min (Dist[j], Dist[index] +map[index][j]); the } the}
POJ 1502 MPI Maelstrom