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 cit**y1-cit**y2 and cit**y1-cit**y3. Then if cit**y1 is occupied by the enemy, we must have 1 highway repaired, that is the highway cit**y2-cit**y3.

Input Specification:

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 Specification:

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

题目大意 给一个图,查询删掉某一个点之后还有几个连通块

思路分析 第五个例子太迷了,写邻接表和前向星都有段错误,不知道前向星是不是开小了,这题点只有1000个,所以还是用最传统的矩阵存储比较好,第五个测试样例接近完全图了都.这种点比较少的图很容易出这种恶心的样例

#include<bits/stdc++.h>
#define de(x) cout<<#x<<" "<<(x)<<endl
#define each(a,b,c) for(int a=b;a<=c;a++)
using namespace std;
const int maxn=1000+5;
const int maxm=1e6+5;
const int inf=0x3f3f3f3f;
//vector<int>G[maxn];
/*
int head[maxn];
struct edge
{
int v;
int next;
}edge[maxm];
int cnt;
void addEdge(int u,int v)
{
edge[cnt].v=v;
edge[cnt].next=head[u];
head[u]=cnt++;
}*/
int a[maxn][maxn];
///段错误?????
/*
3 2 3
1 2
1 3
1 2 3
*/
int ban=0;
bool vis[maxn];
void dfs(int x,int n)
{
vis[x]=true;
for(int i=1;i<=n;i++)
{ if(!vis[i]&&a[x][i]==1)
{
dfs(i,n);
}
}
return;
}
int main()
{
int n,m,q;
cin>>n>>m>>q;
//memset(head,0,sizeof(head));
//cnt=1;
memset(a,0,sizeof(a));
while(m--)
{
int aa,b;
cin>>aa>>b;
a[aa][b]=1;
a[b][aa]=1; //G[a].push_back(b);
//G[b].push_back(a);///别写vector和map了
}
while(q--)
{
int query;
cin>>query; memset(vis,0,sizeof(vis));
vis[query]=true;
int cnt=0;
for(int i=1;i<=n;i++)
{
if(vis[i])continue;
dfs(i,n);
cnt++;
}
printf("%d\n",cnt-1); } }

最新文章

  1. WCF netTcp配置
  2. ue4 build configuration的解释
  3. Apache Commons-pool实现对象池(包括带key对象池)
  4. python中的类简单讲解
  5. nuc970连接jlink进行单步调试的设置
  6. (转)GBDT迭代决策树理解
  7. 前端MVVM框架:Knockout.JS(一)
  8. List转换成JSON对象报错(三)
  9. Unity UGUI之Canvas&amp;EventSystem
  10. python可视化库 Matplotlib 00 画制简单图像
  11. vee-validate的使用
  12. Vim 多行剪切、复制和删除
  13. XMind 入门教程
  14. 雷林鹏分享:jQuery EasyUI 树形菜单 - 创建异步树形菜单
  15. CRM函数CRM_ORDER_MAINTAIN封装
  16. 河南省第四届ACM省赛(T1) 序号互换
  17. python string tuple list dict 相互转换的方法
  18. 找出numpy array数组的最值及其索引
  19. 【BZOJ】4152: [AMPPZ2014]The Captain【SLF优化Spfa】
  20. HTML5游戏开发系列教程10(译)

热门文章

  1. Error: unable to load xmlsec-openssl library
  2. 调用微信公众平台扫一扫示例及解决接口报错 { &quot;errMsg&quot;: &quot;config:invalid signature&quot; }
  3. python 了解一点属性的延迟计算
  4. new Handler()和new Handler(Looper.getMainLooper())的区别是什么?
  5. android studio 错误汇总以及解决办法
  6. Linux下批量解压.Z格式文件
  7. MySQL建表时添加备注以及查看某一张表的备注信息
  8. react中异步的使用
  9. 搭建iOS开发环境
  10. 【Kail 学习笔记】Dmitry信息收集工具