1638: [Usaco2007 mar]cow Traffic Cow traffic

Source: Internet
Author: User

1638: [Usaco2007 mar]cow traffic Cow traffic time limit:5 Sec Memory limit:64 MB
submit:618 solved:217
[Submit] [Status] Description

Farm, due to the rapid increase in the number of cows, the road to the cow's dormitory is also a serious traffic congestion problem. FJ intends to find the busiest way to focus on remediation. This pastoral area consists of a network of M (1≤m≤50,000) Single-line roads (with direction) and an N (1≤n≤5,000) intersection (numbered 1). N), each road is connected to two different intersections. The cow's quarters are located at the nth Junction. Each road is led by a numbered junction leading to a large numbered junction. This avoids loops in the network. It is clear that all roads lead to the cows ' dormitories. The two intersections may be connected by more than one edge. When preparing to go to bed, all cows move from their respective intersection to the cow's dorm, the cows will only be at the junction of 0, and all the entrance to 0 of the intersection will have cows. Help FJ find the busiest road, that is, calculate the maximum number of passes through a road in all paths. The answer is guaranteed to be stored in a 32-bit integer.

Input

First line: Two integers separated by a space: N,m.

The second line to line m+1: two integers separated by spaces Ai,bi each line, representing a road from Ai to BI.

Output

First line: An integer that represents the maximum number of passes through a corridor in all paths.

Sample Input7 7
1 3
3 4
3 5
4 6
2 3
5 6
6 7
Sample Output4
Sample Description:

1 4
\ / \
3 6--7
/ \ /
2 5
All paths leading to the cow's dorm:

1 3 4) 6 7
1 3 5) 6 7
2 3 4) 6 7
2 3 5) 6 7
HINT Source

Silver

The problem: I want to beat the wrong person--the 32-bit integer that was clearly agreed on in the title, but when I was naïve enough to hand in a program that didn't open int64, wa!!! Then I switched to int64, and nothing else changed, ac!!!. Here's This ... OK to get to the point-in fact, only need to follow to find out from the starting point to the various points of the number of paths, and then to find a way from the various points to the number of cows dormitory path (not difficult to write the recursion, this question, oh ah, even the topological sort is exempt ...) And then the number of passes per edge = The path of the source point to the edge of this edge x the number of paths to the cow's dorm, this way, just O (2n+m), easy water over ...

1 type2Point=^node;3Node=Record4 G:longint;5 Next:point;6     End;7 var8 I,j,k,m,n:longint;9 L:int64;TenB:Array[0..6000] ofPoint ; OneC,d:Array[0..6000] ofInt64; A P:point; - procedureAdd (x,y:longint); -           varP:point; the           begin - new (p); -p^.g:=y; -p^.next:=A[x]; +a[x]:=p; -  + new (p); Ap^.g:=x; atp^.next:=B[y]; -b[y]:=p; -           End; - begin - readln (n,m); -       fori:=1  toM Do in          begin - readln (j,k); to Add (j,k); +          End; -       fori:=1  toN Do the          begin *p:=B[i]; $               ifp=Nil  ThenPanax Notoginsengc[i]:=1 -               Else the                   begin +c[i]:=0; A                         whileP<>Nil  Do the                              begin +c[i]:=c[i]+C[P^.G]; -p:=P^.next; $                              End; $                   End; -          End; -d[n]:=1; the       fori:=n-1 Downto 1  Do -          beginWuyip:=A[i]; the               ifp=Nil  Then -d[i]:=0 Wu               Else -                   begin Aboutd[i]:=0; $                         whileP<>Nil  Do -                              begin -d[i]:=d[i]+D[P^.G]; -p:=P^.next; A                              End; +                   End; the          End; -l:=0; $       fori:=1  toN Do the          begin thep:=A[i]; the                whileP<>Nil  Do the                     begin -k:=c[i]*D[P^.G]; inWriteln (I,' ', P^.G,' - ', C[i],' ', D[P^.G]); the                          ifK>l Thenl:=K; thep:=P^.next; About                     End; the          End; the Writeln (l); the End. +                  

1638: [Usaco2007 mar]cow traffic Cow traffic

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.