国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

1013. Battle Over Cities (25)

2019-11-08 01:39:53
字體:
供稿:網(wǎng)友

1013. Battle Over Cities (25)

時間限制400 ms內(nèi)存限制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 31 21 31 2 3Sample Output
100
#include <cstdio>#include <algorithm>#include <vector>using namespace std;const int MAXN = 1010;vector<int> G[MAXN];int N;bool vis[MAXN];void DFS(int v){	vis[v] = true;	for(int i = 0; i < G[v].size(); i ++){		if(!vis[G[v][i]])	DFS(G[v][i]);	}}int DFSTravel(int v){	int cnt = 0;	fill(vis, vis+MAXN, false);//fill(vis, vis+N, false), 因為是從1-N,這樣寫就錯了, vis[n]沒有覆蓋到 	vis[v] = true;	for(int i = 1; i <= N; i ++){		if(!vis[i]){			DFS(i);			cnt ++;		}	}	return cnt;}int main(){	int M, K;	scanf("%d%d%d", &N, &M, &K);	for(int i = 0; i < M; i ++){		int v1, v2;		scanf("%d%d", &v1, &v2);		G[v1].push_back(v2);		G[v2].push_back(v1);	}	for(int i = 0; i < K; i ++){		int v;		scanf("%d", &v);		printf("%d/n", DFSTravel(v)-1);	}	return 0;}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 广水市| 华安县| 色达县| 宜兰县| 进贤县| 泗水县| 九江市| 托里县| 肥乡县| 庐江县| 定安县| 常宁市| 修水县| 安徽省| 定结县| 榕江县| 莱阳市| 黑水县| 安顺市| 崇州市| 石门县| 万年县| 隆昌县| 丰县| 云安县| 叶城县| 桑植县| 樟树市| 长垣县| 南雄市| 岳阳市| 铅山县| 襄汾县| 中西区| 海南省| 固安县| 仪征市| 内江市| 常宁市| 仪征市| 和田市|