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 ;
}

最新文章

  1. GPS 气压计高度测量
  2. 【hive】——Hive基本操作
  3. 在wex5平台grid里面的gridselect下拉不能显示汉字问题
  4. ilspy导致c# dll代码被窃取
  5. HTML5手机APP开发入(5)
  6. [git]fork+pull提交模式
  7. unity3d 赛车游戏——复位点检测优化、反向检测、圈数检测、赛道长度计算
  8. RequestContextListener有什么用
  9. Perl中的匹配(六)
  10. 1:CSS中一些@规则的用法小结 2: @media用法详解
  11. LA 4329(树状数组)
  12. Linux批量替换文本,文件夹内所有文本内容
  13. JS面向对象,创建,继承
  14. 在centos6,7 上编译安装内核
  15. bootstrap模态对话框
  16. Leetcode_122_Best Time to Buy and Sell Stock II
  17. 第四课 VMP壳内爆破
  18. VMware搭建虚拟机服务器
  19. C# 连接Oracle时报错的问题
  20. Ubuntu Eclipse C++运行问题:launch failed.Binary not found

热门文章

  1. c#帮助类:发送邮件
  2. Vue 父组件主动获取子组件的值,子组件主动获取父组件的值
  3. C++内存管理之shared_ptr
  4. JavaScript 如何工作:渲染引擎和性能优化技巧
  5. django使用auth模块进行身份认证
  6. Web 安全入门-书籍及建议
  7. MongDB from execCommand not master
  8. 跟我一起读postgresql源码(一)——psql命令
  9. SDUT OJ 学密码学一定得学程序
  10. JS 对象的三种创建方式