Bzoj 1574: [Usaco2009 Jan] earthquake damage damage

Source: Internet
Author: User

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.

Solution: from 1 to the outside of the BFS, obviously the answer to the replenishment of the point VC any one of the linked points can not be given the point

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <queue>5 #defineMAXN 4000096 using namespacestd;7 intHead[maxn],nex[maxn],point[maxn],now =0, VISIT[MAXN];8 intA[MAXN];9 voidAddintXinty)Ten { OneNex[++now] =Head[x]; AHEAD[X] =Now ; -Point[now] =y; - } the intBFsints) - { -queue<int>Q; - Q.push (s); +Visit[s] =1; -     intCNT =0; +      while(!q.empty ()) A     { at         intU = Q.front (), flag =0; - Q.pop (); -          for(inti = Head[u]; I i =Nex[i]) -         { -             intU =Point[i]; -             if(A[u]) in             { -Flag =1; to                  Break; +             } -         } the         if(flag)Continue; *cnt++; $          for(inti = head[u];i;i=Nex[i])Panax Notoginseng         { -             intK =Point[i]; the             if(Visit[k])Continue; +VISIT[K] =1; A Q.push (k); the         } +     } -     returnCNT; $ } $ intMain () - { -     intp,c,n,x,y; thescanf"%d%d%d",&p,&c,&n); -      for(intI=1; i<=c;i++)Wuyi     { thescanf"%d%d",&x,&y); - Add (x, y); Wu Add (y,x); -     } About      for(intI=1; i<=n;i++) $     { -scanf"%d",&x); -A[X] =1; -     } A     intU = BFS (1); +printf"%d\n", P-u); the     return 0; -}

Bzoj 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.