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. angular 中间人模式

    import { Component, OnInit, EventEmitter, Output } from '@angular/core'; @Component({ selector: 'app ...

  2. go channel缓冲区的大小

    go channel缓冲区的大小 len也可以作用于channel,代表现在channel缓冲区中还有多少数据没有读取.示例如下 c:=make(chan int,20) fmt.Println(&q ...

  3. 《javascript 高级程序设计》 笔记2 8~章

    chapter 8 BOM(浏览器对象模型) window对象 表示浏览器的一个实例. 直接在window对象上定义的属性可以通过delete操作符删除,而全局变量不可以. 窗口关系及框架 位置操作 ...

  4. winform datagridview数据显示不全

    如果是内容是汉字,列的宽度设置不够时会自动换行,如果是数字和字母,是不会自动换行的,要把列宽设得足够,整个表格显示不全时,下面会有横向滚动条,如果看不见可能是高度超出了母控件的高度,设得低点就看见了

  5. bzoj2115(线性基)

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2115 题意:求图中路径1~n上最大边权 xor 和 思路:参见 blog http://b ...

  6. Link cut tree 实现不高效的 LCA

    https://www.luogu.org/problemnew/show/P3379 求 a 和 b 的 LCA 考虑先 access(a),此时 a 和 root 在一条链上,再 access(b ...

  7. 【BlockingQueue】BlockingQueue 阻塞队列实现

    前言: 在新增的Concurrent包中,BlockingQueue很好的解决了多线程中,如何高效安全“传输”数据的问题.通过这些高效并且线程安全的队列类,为我们快速搭建高质量的多线程程序带来极大的便 ...

  8. 洛谷 P2096 最佳旅游线路

    某旅游区的街道成网格状.其中东西向的街道都是旅游街,南北向的街道都是林阴道.由于游客众多,旅游街被规定为单行道,游客在旅游街上只能从西向东走,在林阴道上则既可从南向北走,也可以从北向南走. 阿龙想到这 ...

  9. javascript中类数组转成真正的数组

    function list() { return Array.prototype.slice.call(arguments); } var list1 = list(1, 2, 3); // [1, ...

  10. Eclipse 使用TFS

    Install Soft , –> add http://dl.microsoft.com/eclipse/tfs   form:http://msdn.microsoft.com/en-us/ ...