3402: [Usaco2009 open]hide and seek hide and seek time limit:3 Sec Memory limit:128 MB
submit:78 solved:64
[Submit] [Status] Description Bessie was playing a "hide and seek" game with John. She was about to find out all the safe sheds that fit her hide. A total of N (2≤n≤20000) of the barn, was compiled into 1 to N. She knew that John (the bull-Trapper) had departed from the barn 1. All the barns are connected by M (1≤m≤50000) bidirectional Road, each bidirectional road connected to two different cattle sheds. All the barns are connected. Bessie believed that the barn 1 farthest from the barn was safe. The distance between the two barns means the minimum number of roads that need to be passed from one barn to another. Please help Betsy find all the safe sheds. Input line 1th enters two integers n and M, followed by a two integer for each row of M lines, representing two endpoints of a path. Output
Only one row, output three integers. The 1th represents a safe bullpen (if there are more than one, the output number is the smallest); the 2nd represents the distance between the Barn 1 and the safe bullpen; The 3rd indicates how many safe barns there are.
Sample Input6 7
6 S
4 3
3 2
1 3
1 2
2 4
5 2Sample Output4 2 3HINT Source
Silver
The puzzle: Needless to say, the obvious single source the shortest, but there is a very magical episode-the beginning with Dijkstra write, the results of tle very miserable, then replaced by SPFA, then 192ms ac?!?!
So, I intend to start the next experimental study, and will probably consider the introduction of heap-optimized Dijkstra, as well as the introduction of the Floyd algorithm when the full-source shortest path to compare, please look forward to
1/**************************************************************2Problem:34023 User:hansbug4 language:pascal5 result:accepted6Time:192Ms7Memory:13904KB8****************************************************************/9 Ten type OnePoint=^node; ANode=Record - G,w:longint; - Next:point; the End; - var - I,j,k,l,m,n,f,r:longint; -A:Array[0..100000] ofPoint ; +B,c,d:Array[0..1000000] ofLongint; - P:point; + procedureAdd (x,y,z:longint); A varP:point; at begin -New (p);p ^.g:=y;p^.w:=Z; -p^.next:=a[x];a[x]:=p; - End; - functionmin (x,y:longint): Longint; - begin in ifX<y ThenMin:=xElsemin:=y; - End; to begin + readln (n,m); - fori:=1 toN Doa[i]:=Nil; the fori:=1 toM Do * begin $ readln (j,k);Panax NotoginsengAdd (J,k,1); Add (K,j,1); - End; thef:=1; r:=2; +Fillchar (C,sizeof (c),0); Ab[1]:=1; c[1]:=1; the + whileF<r Do - begin $p:=A[b[f]]; $ whileP<>Nil Do - begin - if(c[p^.g]=0)or(C[p^.g]> (C[B[F]]+P^.W)) Then the begin -b[r]:=p^.g;Wuyic[p^.g]:=c[b[f]]+P^.W; the Inc (R); - End; Wup:=P^.next; - End; About Inc (f); $ End; -j:=0; k:=0; l:=0; - fori:=1 toN Do - ifC[i]>j Then A begin +j:=C[i]; thek:=1; -l:=i; $ End the Else ifC[i]=j ThenInc (k); theWriteln (L,' ', J-1,' ', k); the End.
3402: [Usaco2009 open]hide and seek hide and seek