(这是水题)pat-1013
2015-10-24 20:13
387 查看
1013. Battle Over Cities (25)
时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueIt 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 citiesconnected. 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 isoccupied by the enemy, we must have 1 highway repaired, that is the highway city2-city3.InputEach 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.OutputFor each of the K cities, output in a line the number of highways need to be repaired if that city is lost.Sample Input3 2 3 1 2 1 3 1 2 3Sample Output
1 0 0
dfs过,不用割点。。。。。好像有个三十分的,是顶级的得用割点,这个简单dfs过了。
代码:
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int mp[1010][1010]; int vis[1010]; int n; void dfs(int x){ for(int i = 1;i<=n;i++){ if(vis[i] == 0&&mp[x][i] == 1){ vis[i] = 1; dfs(i); } } } int main(){ int m,k; memset(mp,0,sizeof(mp)); scanf("%d%d%d",&n,&m,&k); int a,b; for(int i = 0;i<m;i++){ scanf("%d%d",&a,&b); mp[a][b] = mp[b][a] = 1; } int x; for(int i = 0;i<k;i++){ scanf("%d",&x); int ans = 0; memset(vis,0,sizeof(vis)); vis[x] = 1; for(int i = 1;i<=n;i++){ if(vis[i] == 0){ ans ++; dfs(i); } } printf("%d\n",ans-1); } }
相关文章推荐
- 不是每次做坏事都会被发现之——嵌入式编程中的内存管理
- Raspberry Pi 初始化
- kettle6.0linux安装配置
- pentaho bi server5.4MySQL部署
- C#中部分方法使用的一个细节
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest I题:Illegal or Not? [暴力题]
- window7下用wubi安装ubuntu
- 项目开发,我的名字不可能这么可爱——使用XML和Sqlite处理数据
- 关于spring的@resource注解的字段注入和setter注入的区别
- UML图总结
- UIScrollView的简单介绍
- MFC的oncreate函数作用
- 寒门再难出贵子
- 承诺c指针 (1)指针是地址
- poj 2002 hash
- 分享一个解析html的python的框架--AdvancedHTMLParser
- 一个一维整形数组,若干个数字,统计数组中不同的数字出现的次数,并按照出现频率从小到大排序输出,相同频率按数字大小排序输出
- 机器学习之K近邻算法(KNN)
- xcode非app store安装方法
- 异步(ajax)配合一般处理程序 验证用户名