博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1013. Battle Over Cities (25)(DFS遍历)
阅读量:7286 次
发布时间:2019-06-30

本文共 1432 字,大约阅读时间需要 4 分钟。

 

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 31 21 31 2 3

Sample Output

100 题目大意:给出n个城市之间有相互连接的m条道路,当删除一个城市和其连接的道路的时候,         问其他几个剩余的城市至少要添加多少个路线才能让它们重新变为连通图,其实就是求连通分支数
1 #include
2 #include
3 #include
4 5 int graph[1001][1001]; 6 int visited[1001]; 7 int n,m,k; 8 void dfs( int a) 9 {10 int i;11 visited[a]=1;12 for( i=1; i<=n; i++)13 {14 if( visited[i]==0 && graph[a][i]==1)15 dfs(i);16 }17 }18 int main()19 {20 int cnt=0,temp;21 int i,j;22 int a,b;23 scanf("%d%d%d",&n,&m,&k);24 for( i=0; i

 

 

转载于:https://www.cnblogs.com/yuxiaoba/p/8553461.html

你可能感兴趣的文章
OpenSSL命令之算法类大全
查看>>
MailBee.NET Objects发送电子邮件(SMTP)教程八:使用多个SMTP服务器发送邮件
查看>>
如何在VS CODE调试Angular
查看>>
学习Linux系统的方法有很多,适合自己的才是最好。
查看>>
DRAM和NAND Flash合约价持续走下坡路
查看>>
KVM网桥
查看>>
初尝- 搭建数据库MySql环境
查看>>
Yii2页面缓存详解
查看>>
ECMAScript正则表达式6个最新特性
查看>>
android Studio 快捷键
查看>>
MySQL Explain
查看>>
Java NIO
查看>>
1、图片水印 之 一
查看>>
分布式锁
查看>>
使用proxychains-ng代理转发终端命令
查看>>
mysql初始化错误
查看>>
shell中的函数,shell中的数组,告警系统需求分析
查看>>
df命令 、du命令 、磁盘分区
查看>>
Java并发编程:CountDownLatch、CyclicBarrier和 Semaphore
查看>>
使用JDK自带的jmap和jhat监控处于运行状态的Java进程
查看>>