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

Input

Each input file contains one test case. Each case starts with a line containing 3 numbers N (<1000), M and K, which are 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 are the numbers of the cities the highway connects. The cities are 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 3
1 2
1 3
1 2 3

Sample Output

1
0
0
题目大意:给出n个城市之间有相互连接的m条道路,当删除一个城市和其连接的道路的时候,
问其他几个剩余的城市至少要添加多少个路线才能让它们重新变为连通图,其实就是求连通分支数
 #include<stdio.h>
#include<string.h>
#include<stdlib.h> int graph[][];
int visited[];
int n,m,k;
void dfs( int a)
{
int i;
visited[a]=;
for( i=; i<=n; i++)
{
if( visited[i]== && graph[a][i]==)
dfs(i);
}
}
int main()
{
int cnt=,temp;
int i,j;
int a,b;
scanf("%d%d%d",&n,&m,&k);
for( i=; i<m; i++) //创建图
{
scanf("%d%d",&a,&b);
graph[a][b]=graph[b][a]=;
}
for( i=; i<k ; i++)
{
cnt=;
memset( visited,,sizeof(visited)); //每次都将visited全置0
scanf("%d",&temp);
visited[temp]=;
for( j=; j<=n; j++)
{
if( visited[j]==)
{
dfs(j);
cnt++; //连通分支数
}
}
printf("%d\n",cnt-); //需要建的高速为连通分支数减1
}
return ;
}
												

1013. Battle Over Cities (25)(DFS遍历)的更多相关文章

  1. 1013 Battle Over Cities (25分) DFS | 并查集

    1013 Battle Over Cities (25分)   It is vitally important to have all the cities connected by highways ...

  2. PAT 甲级 1013 Battle Over Cities (25 分)(图的遍历,统计强连通分量个数,bfs,一遍就ac啦)

    1013 Battle Over Cities (25 分)   It is vitally important to have all the cities connected by highway ...

  3. PAT 解题报告 1013. Battle Over Cities (25)

    1013. Battle Over Cities (25) t is vitally important to have all the cities connected by highways in ...

  4. PAT Advanced 1013 Battle Over Cities (25) [图的遍历,统计连通分量的个数,DFS,BFS,并查集]

    题目 It is vitally important to have all the cities connected by highways in a war. If a city is occup ...

  5. 1013 Battle Over Cities (25分) 图的连通分量+DFS

    题目 It is vitally important to have all the cities connected by highways in a war. If a city is occup ...

  6. 1013 Battle Over Cities (25 分)

    It is vitally important to have all the cities connected by highways in a war. If a city is occupied ...

  7. 1013. Battle Over Cities (25)

    题目如下: It is vitally important to have all the cities connected by highways in a war. If a city is oc ...

  8. PAT A 1013. Battle Over Cities (25)【并查集】

    https://www.patest.cn/contests/pat-a-practise/1013 思路:并查集合并 #include<set> #include<map> ...

  9. 1013. Battle Over Cities 用dfs计算联通分量

    使用一个标记数组,标记 节点是否已访问 int 连通度=0 dfs(node i) {标记当前节点为以访问 for(每一个节点) {if(当前几点未访问 并且 从i到当前节点有直接路径) dfs(当前 ...

随机推荐

  1. RHEL 6.5----SCSI存储

    主机名 IP master 192.168.30.130 node-1 192.168.30.131 node-2 192.168.30.132 安装并启动 [root@master ~]# ll / ...

  2. Unity中所有特殊的文件夹

    1. 隐藏文件夹以.开头的文件夹会被Unity忽略.在这种文件夹中的资源不会被导入,脚本不会被编译.也不会出现在Project视图中.2. Standard Assets在这个文件夹中的脚本最先被编译 ...

  3. 新建cordova应用

    使用命令行(本例命令行均使用as或webstrom的命令行),在任意目录输入以下命令新建cordova应用 cordova create capp1 com.cesc.ewater.capp1 其中c ...

  4. Android开发精品收藏贴

    各种下拉刷新效果: https://github.com/scwang90/SmartRefreshLayout

  5. What is Scalability?

    Scalability is a system's ability to process more workload, with a proportional increase in system r ...

  6. IOS之UIStepper控件详解

    在iOS5中新增了一个数字输入控件UIStepper,它可以递进式输入数量.UIStepper继承自UIControl,它主要的事件是UIControlEventValueChanged,每当它的值改 ...

  7. Selenium私房菜系列3 -- Selenium API参考手册【ZZ】

    大家在编写测试案例想查阅Selenium API说明时,可以查阅本文,否则请跳过! (注:这里API版本比较老,新版本的Selenium的API在这里不一定能找到.) Selenium API说明文档 ...

  8. swift版本拼图游戏项目源码

    现学现做的第一个swift版本拼图游戏demo 常规模式,对换模式任你选择, 用到了花瓣的API,各种萌妹子~

  9. 螺旋数字的python实现

    螺旋数字的算法简单实现. 示例 5 01 02 03 04 05 16 17 18 19 06 15 24 25 20 07 14 23 22 21 08 13 12 11 10 09 通过观察,外部 ...

  10. HTML5应用 + Cordova = 平台相关的混合应用

    Jerry之前的一篇文章 SAP Fiori应用的三种部署方式 曾经提到SAP Fiori应用的三种部署方式: On Premise环境下以ABAP BSP应用作为Fiori应用部署和运行的载体 部署 ...