A1013. Battle over Cities (25)

Source: Internet
Author: User

It is vitally important to has all the cities connected by highways in a war. If a city was occupied by the enemy, all of the highways From/toward that city was closed. We must know immediately if we need to repair all other highways to keep the rest of the cities connected. Given the map of cities which has all the remaining highways marked, you is supposed to tell the number of highways need To be repaired, quickly.

For example, if we have 3 cities and 2 highways connecting City1-city2 and City1-city3. Then if city1 are occupied by the enemy, we must has 1 highway repaired, which is the highway city2-city3.

Input

Each input file contains the one test case. Each case starts with a line containing 3 numbers N (<1000), M and K, which is the total number of cities, the number of remaining highways, and the number of cities to be checked, respectively. Then M. lines follow, each describes a highway by 2 integers, which is the numbers of the cities of Highway. The cities is numbered from 1 to N. Finally There is a line containing K numbers, which represent the cities we concern.

Output

For each of the K-cities, output in a line the number of highways need to be repaired if that city is lost.

Sample Input
3 2 31 21 31 2 3
Sample Output
100
1#include <stdio.h>2#include <stdlib.h>3#include <iostream>4#include <string.h>5#include <math.h>6#include <algorithm>7#include <string>8#include <stack>9#include <queue>Ten#include <vector> One using namespacestd; A Const intmaxn=1010; - intFATHER[MAXN]; - intVIS[MAXN]; the intn,m,k; -vector<int>G[MAXN]; - voidInit () - { +      for(intI=1; i<maxn;i++) -     { +father[i]=i; Avis[i]=false; at     } -  }  -  intIsfather (intx) -  { -      inttmp=x; -       while(x!=Father[x]) in      { -x=Father[x];  to     } +     //Thus, x is the root of the collection -      while(tmp!=father[tmp]) the     { *         intz=tmp; $tmp=father[tmp];Panax Notoginsengfather[z]=x; -     } the     returnx; +  } A   the voidUnion (intAintb) + { -       intFa=Isfather (a); $     intfb=Isfather (b); $     if(fa!=FB) -     { -father[fa]=FB; the      }  - } Wuyi  the  -  Wu intMain () { -scanf"%d%d%d",&n,&m,&k); About    for(intI=0; i<m;i++) $   { -       intc1,c2; -scanf"%d%d",&c1,&C2); - g[c1].push_back (C2); A G[c2].push_back (C1); +   } the    for(intI=0; i<k;i++) -   { $       inttmp; thescanf"%d",&tmp); the       //eliminating the connected edges of the TMP point, and then calculating the number of separated blocks, all the repair edges can be obtained . the     //Traverse the init (); -     //Merging Collections in      for(intI=1; i<=n;i++) the     { the         for(intj=0; J<g[i].size (); j + +) About        { the            intv=G[i][j]; the            if(v!=tmp&&i!=tmp) Union (i,v); the        }     +     } -      the     intblock=0;Bayi      for(intI=1; i<=n;i++) the     { the         if(i==tmp)Continue; -         if(I==father[i]) block++; -      }  theprintf"%d\n", block-1); the   } the   return 0; the}

A1013. Battle over Cities (25)

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.