HDOJ066 乙個人的旅行 dijkstra

2021-07-04 10:40:31 字數 1321 閱讀 9959

problem description

input

輸入資料有多組,每組的第一行是三個整數t,s和d,表示有t條路,和草兒家相鄰的城市的有s個,草兒想去的地方有d個;

接著有t行,每行有三個整數a,b,time,表示a,b城市之間的車程是time小時;(1=<(a,b)<=1000;a,b 之間可能有多條路)

接著的第t+1行有s個數,表示和草兒家相連的城市;

接著的第t+2行有d個數,表示草兒想去地方。

output

輸出草兒能去某個喜歡的城市的最短時間。

sample input

6 2 3

1 3 5

1 4 7

2 8 12

3 8 4

4 9 12

9 10 2

1 28 9 10

sample output

9

author

grass

模板題 注意與草兒家相連城市的初始化即可

ac**:

#include "iostream"

#include "cstdio"

#include "cstring"

#include "algorithm"

using namespace std;

int t, s, d, n, map[1005][1005], d1[1005], ans[1005];

bool vis[1005];

const int inf = 0x3f3f3f3f;

void dijkstra()

vis[x] = true;

for(int j = 1; j <= n; ++j)

if(ans[x] + map[x][j] < ans[j] && !vis[j])

ans[j] = ans[x] + map[x][j];

}}int main(int argc, char const *argv)

int s1;

for(int i = 0; i < s; ++i)

for(int i = 0; i < d; ++i)

cin >> d1[i];

dijkstra();

int ans_ = inf;

for(int i = 0; i < d; ++i)

ans_ = min(ans_, ans[d1[i]]);

cout << ans_ << endl;

}return 0;

}

hdoj2066乙個人的旅行

total submission s 24946 accepted submission s 8675 problem description input 輸入資料有多組,每組的第一行是三個整數t,s和d,表示有t條路,和草兒家相鄰的城市的有s個,草兒想去的地方有d個 接著有t行,每行有三個整數a,...

hdoj 2066乙個人的旅行

這題最重要的就是設定乙個超級原點,即他的城鎮,然後連線超級原點到相鄰的城市的距離為0 接下來就是套用模板了,哦,對了,要優化一下,不然貌似資料蠻大的,view code 1 include stdio.h 2 include math.h 3 include string.h 4 define ma...

乙個人旅行

乙個人旅行計畫正式啟動啦 一直想乙個人好好的出去走走轉轉.然後把遇到的看到的記錄下來,成為回憶.但是一直沒有鼓起勇氣或者說沒有找到好的藉口.經過長達四年的準備 嘿嘿,有點誇張 目前各方面已經就緒 2008年12月份 公園瀏覽年票 到位 2009年5月份 確實地說是上周五 2009.05.08 富士相...