1574: [Usaco2009 Jan] earthquake damage damage

Source: Internet
Author: User

1574: [Usaco2009 Jan] earthquake damage damage time limit:10 Sec Memory limit:64 MB
submit:425 solved:232
[Submit] [Status] [Discuss] Description

The farmer John's farm suffered an earthquake. Some of the cattle sheds were damaged, but fortunately, all the road stalls between the cattle can be used. FJ's Farm has P (1 <= p <= 30,000) a barn, number 1. P. C (1 <= C <= 100,000) Two-way road through connection these sheds, numbered 1. C. Road Meridian I connect the bullpen a_i and b_i (1 <= a_i<= p;1 <= b_i <= P). The road may connect a_i to itself, and there may be multiple pathways between the two barns. The farm is in the barn numbered 1. N (1 <= n <= p) head in different cattle cows by SMS Report_j (2 <= report_j <= P) told FJ their bullpen (Report_j) was not damaged, but they could not go back to the farm through the road and the undamaged bullpen. When FJ receives all the text messages, find out the smallest number of barns that are unlikely to return to the farm. This number includes the damaged bullpen. Note: The first 50 commits will provide running results on some test data.

Input

* Line 1th: Three spaces separate number: P, C, and N

* 2nd. C+1 lines: Two spaces per line: a_i and B_i * c+2..c+n+1 line: One number per line: Report_j

Output

* Line 1th: Number of cows that cannot return to the farm at least (including damaged barns).

Sample Input4 3 1
1 2
2 3
3 4
3


Sample Output3

HINT

The Barn 2 was damaged, resulting in a cattle barn 2, 3, 4 cows could not return to the farm.

Source

Gold

The main idea: first saw the damage what to think of cutting, and then can not help to the maximum flow of the smallest cut above thought, it turns out I think more ... Tt

A search problem, for the least cut point of the case, must be damaged the barn just good can be sent to the point of the message is not able to connect to 1, and then according to the situation to find an optimal cutting situation, and then directly DFS out of the optimal cutting situation is still connected points, and then use N minus the finished.

1 type2Point=^node;3Node=Record4 G:longint;5 Next:point;6     End;7 var8 I,j,k,l,m,n,t,ans:longint;9A:Array[0..100000] ofPoint ;TenB,c,d:Array[0..100000] ofLongint; One P:point; A procedureAdd (x,y:longint); inline; -           varP:point; -           begin theNew (p);p ^.g:=y;p^.next:=a[x];a[x]:=p; -           End; - procedureDFS (x:longint); inline; -           varP:point; +           begin -                ifB[x]<>0  Thenexit; +Inc (ANS); b[x]:=1; Ap:=A[x]; at                 whileP<>Nil  Do -                      begin -                           ifb[p^.g]=0  ThenDFS (P^.G); -p:=P^.next; -                      End; -           End; in begin - readln (n,m,t); to       fori:=1  toN Doa[i]:=Nil; +       fori:=1  toM Do -          begin the readln (j,k); * Add (j,k); add (k,j); $          End;Panax NotoginsengFillchar (b,sizeof (b),0); -       fori:=1  toT Do the          begin + Readln (j); Ab[j]:=1; thep:=A[j]; +                whileP<>Nil  Do -                     begin $                          ifb[p^.g]=0  Thenb[p^.g]:=-1; $p:=P^.next; -                     End; -          End; the       fori:=1  toN Do ifb[i]=1  Thenb[i]:=-1; -ans:=0;WuyiDfs1); theWriteln (nans); - End.

1574: [Usaco2009 Jan] earthquake damage damage

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.