a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

uva 11463 Commandos

2019-11-11 05:12:16
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

A group of commandos were assigned a critical task. They are to destroy an enemy head quarter. The enemy head quarter consists of several buildings and the buildings are connected by roads. The commandos must visit each building and place a bomb at the base of each building. They start their mission at the base of a particular building and from there they disseminate to reach each building. The commandos must use the available roads to travel between buildings. Any of them can visit one building after another, but they must all gather at a common place when their task in done. In this PRoblem, you will be given the description of different enemy headquarters. Your job is to determine the minimum time needed to complete the mission. Each commando takes exactly one unit of time to move between buildings. You may assume that the time required to place a bomb is negligible. Each commando can carry unlimited number of bombs and there is an unlimited supply of commando troops for the mission.

Input Input starts with an integer T (≤50), denoting the number of test cases.

The first line of each case starts with a positive integer N (1 ≤ N ≤ 100), where N denotes the number of buildings in the head quarter. The next line contains a positive integer R, where R is the number of roads connecting two buildings. Each of the next R lines contain two distinct numbers u v (0 ≤ u, v < N), this means there is a road connecting building u to building v. The buildings are numbered from 0 to N-1. The last line of each case contains two integers s d (0 ≤ s, d < N). Where s denotes the building from where the mission starts and d denotes the building where they must meet. You may assume that two buildings will be directly connected by at most one road. The input will be given such that, it will be possible to go from any building to another by using one or more roads.

Output For each case, print the case number and the minimum time required to complete the mission.

Sample Input 2 4 3 0 1 2 1 1 3 0 3 2 1 0 1 1 0 Sample Output Case 1: 4 Case 2: 1

題目:有一個(gè)敢死隊(duì),要摧毀一群建筑,他們從一個(gè)特定的建筑出發(fā),最后到一個(gè)特定的建筑集合;

現(xiàn)在給你各個(gè)建筑之間的連接路線,在建筑中穿梭需要1個(gè)單位時(shí)間,問(wèn)集合的最早時(shí)間。

分析:圖論,最短路徑。直接計(jì)算起點(diǎn)s和終點(diǎn)e到那個(gè)其他所有點(diǎn)的最短路徑; floyd比較簡(jiǎn)單 也可以用兩個(gè)dijk 因?yàn)閿?shù)據(jù)小。

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;const int maxn = 101000;#define inf 0x3f3f3f3fint d[200];int s[200];int e[200][200];int main(){ int t; cin>>t; int cc=1; while(t--) { int n,m; cin>>n>>m; memset(e,0x3f,sizeof(e)); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) e[i][j]=inf; e[i][i]=0; } for(int i=0;i<m;i++) { int a,b; cin>>a>>b; e[a][b]=1; e[b][a]=1; } int si,di; cin>>si>>di; for(int i=0;i<n;i++) for(int j=0;j<n;j++) for(int k=0;k<n;k++) { if(e[j][k]>e[j][i]+e[i][k]) e[j][k]=e[j][i]+e[i][k]; } int maxx=0; for(int i=0;i<n;i++) maxx=max(e[si][i]+e[i][di],maxx); printf("Case %d: %d/n",cc++,maxx); }}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 成人超碰在线观看 | 国精日本亚洲欧州国产中文久久 | 四虎最新入口 | 欧美一级毛片免费看 | 亚洲天堂精品在线观看 | 国产成人精品视频在线观看 | 午夜激情影院 | 色天天综合久久久久综合片 | 成人欧美一区二区三区在线播放 | 久草福利视频 | 日本超碰 | 自拍偷拍亚洲欧美 | 国产精品久久精品 | 久久av免费观看 | 欧美日韩精品综合 | 日韩精品视频在线观看免费 | 精品一区二区在线观看 | 成年无码av片在线 | 国产欧美一区二区精品久久 | 亚洲一区中文字幕 | 一区二区三区精品视频 | 久久无码精品一区二区三区 | 亚洲精品久久久久久久久久久久久 | 精品久久久久久久久久久久 | 欧美日韩国产综合在线 | 99精品亚洲国产精品久久不卡 | 国产免费av一区二区三区 | 国产精品丝袜视频 | 国产精品久久久久久久7电影 | 99久久精品免费看国产四区 | 91在线中文字幕 | 日韩一区二区在线观看 | 亚洲视频一区二区三区 | 黄色影视片 | 国产精品一区二区三区四区在线观看 | 看全黄大色黄大片老人做 | 欧美国产日韩在线观看 | 久久久免费av | 欧美日韩精品一二区 | 黄91视频 | www.久久精品视频 |