1013. Battle Over Cities (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any other highways to keep the rest of the cities connected. Given the map of cities which have all the remaining highways marked, you are 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 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

提交代码

判断图的联通分量个数。并查集。

 #include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <iostream>
using namespace std;
int f[];
int getf(int i){
if(f[i]==-){
return i;
}
return f[i]=getf(f[i]);
}
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
int n,m,k;
scanf("%d %d %d",&n,&m,&k);
int *u=new int[m];
int *v=new int[m];
int i,j;
for(i=;i<m;i++){
scanf("%d %d",&u[i],&v[i]);
}
int pnum;
for(i=;i<k;i++){
memset(f,-,sizeof(f));
scanf("%d",&pnum);
for(j=;j<m;j++){
if(u[j]!=pnum&&v[j]!=pnum){
int fu=getf(u[j]);
int fv=getf(v[j]);
if(fu!=fv){
f[fv]=fu;
}
}
}
int count=;
for(j=;j<=n;j++){
if(f[j]==-){
count++;
}
}
count-=;
cout<<count<<endl;
}
delete []u;
delete []v;
return ;
}

pat1013. Battle Over Cities (25)的更多相关文章

  1. PAT-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 occupied ...

  2. PAT---1013. Battle Over Cities (25)

    这道题目的意思是:在战争时代,如果一个城市被敌人占领了,那么和该城市相连的道路都必须关闭,我们必须把剩下的城市(即不包括被敌人占领的城市)连接起来. 举个例子,我们有3个城市,C1,C2,C3,C1和 ...

  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. PAT1013: Battle Over Cities

    1013. Battle Over Cities (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...

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

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

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

  7. Battle Over Cities (25)(DFS、连通图)

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

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

  9. 1013 Battle Over Cities (25)(25 point(s))

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

随机推荐

  1. JAVA8 Lambda 表达式使用心得

    List<HashMap> 指定数据求和: List<HashMap> kk = new ArrayList<>();        Map mmm = new H ...

  2. atp

    一. 新建atp目录,该目录下包含bin(存放启动程序等).config(存放配置程序).lib(存放过程程序).logs(存放生成的日志).cases(存放用例的excel文件)五个目录,并新建一个 ...

  3. J2EE 的体系结构

    J2EE 即Java2平台企业版,它提供了基于组件的方式来设计.开发.组装和部署企业应用.J2EE使用多层分布式的应用模型,这个多层通常通过三层或四层来实现: 1.客户层,运行在客户计算机上的组件.  ...

  4. 谈谈你对Java平台理解

    一说起对Java理解很容易就联想到Java的一些特性: 1,面向对象(继承,多态,封装) 2,平台无关性(”一次书写,到处运行“,jvm运行.class文件) 3,语言(泛型,lambda) 4,类库 ...

  5. go的三个常用命令go run go build go install

    go的三个常用命令 go run go build go install 命令源码文件:含有 main函数 的文件 库源码文件:不包含 main函数 的文件, 主要用于编译成静态文件.a供其他包调用 ...

  6. redux超易学三篇之二(开始使用react-redux)

    其实 redux 真正让人感到混乱的还是在 react-redux 的使用中. 请配合完整代码参考~:完整源代码 也不是说混乱,主要是网上 推崇 最佳实践.学习一个新东西的时候,本来就很陌生,上来就用 ...

  7. requests 模块使用代理

    正向代理与反向代理的区别 反向代理: 服务器端知道代理的存在,反向代理是为了保护服务器或负责负载均衡 但是客户端不知道代理的存在的 正向代理: 客户端知道代理的存在,正向代理是为保护客户端,防止追究责 ...

  8. C++_异常3-异常机制throw try catch

    下面介绍如何使用异常机制来处理错误. C++异常是对程序运行过程中发生的异常情况的一种响应. 异常提供了将控制权从程序的一部分传递到另一部分的途径. 对异常的处理有3个组成部分: 1)引发异常  -- ...

  9. 2.在centos7虚拟机搭建nginx网站

    1.nginx配置目录 cd /etc/nginx/conf.d/ 添加 vi www.18cat.conf server{ listen 80; server_name www.18cat.com; ...

  10. vector与array之间转换,向量与数据之间转换

    一维数组: vector<int> a; int b[5] = {1,2,3,4,5}; a.push_back(b);   二维数组: b[5][6] = {1,2,3,4,5,6... ...