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

/*after removing a node in a connected graph, you need to add at least a few sides to connect the remaining nodes 1. Use DFS to find the number of regions minus 1. The node that was removed has its visited[i] set to 1 and the nodes connected through that node in DFS are separated. */#include"iostream"#include"CString"using namespacestd;#defineMAX 1001intMap[max][max];intVisited[max];intN, M, K;voidDfsintj) {Visited[j]=1;  for(inti =1; I <= N; i++) {        if(!visited[i] && map[j][i] = =1) {DFS (i); }    }}intMain () {CIN>> n >> M >>K;  while(m--) {        intA, B; CIN>> a >>b; MAP[A][B]= Map[b][a] =1; }     while(k--) {        intnum =0; intl; CIN>>l; Memset (visited,0,sizeof(visited)); VISITED[L]=1;  for(intI=1; i<=n; i++)            if(!Visited[i])                {DFS (i); Num++; } cout<< Num-1<<Endl; }        return 0;}

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