XZC的畢業旅行計劃 Apare_xzc

XZC的畢業旅行計劃

時間限制:1000ms
內存限制:256M


題面:

        XZC打算畢業旅行,要從出發地出發到達目的地。地圖有n個城市,m條雙向高鐵線路。你能幫他找到一條最省錢,而且中轉最少的路線嗎?他還是一個學生黨,所以首先要保證從出發地到目的地的高鐵票費用(因爲普快是在是太慢了,他回家要坐20個小時,他受夠了這種感覺)和食宿費等最少。在最省錢的基礎上,他希望中轉的次數最少,畢竟中轉是一件很麻煩的事情,人生地不熟的…聰明的你能幫幫他嗎?
        他有k個詢問,每個詢問可能有不同的出發和目的地。目的地是要旅行的城市。那麼爲什麼出發地也不同呢?這還不簡單?因爲他可能在學校,和室友們吃完大餐以後出發,也可能在別的城市,實習完再出發,也可能先回家一趟,收拾好東西從家出發,還可能先去npy家玩一下再一起去旅行23333。對於每個詢問,他希望你詳細地爲他推薦一條價格最便宜,中轉還最少的路線。你有一個地圖,上面顯示了最新的高鐵線路和票價。你來幫幫他叭~


輸入格式:

  • 多組輸入(因爲高鐵票價和線路是動態改變的,所以在輸入文件中我們有多組輸入)
  • 每個測試文件,第一行是一個正整數T(T<=5) 代表數據的組數,接下來是T組數據
  • 每組數據的第一行是兩個正整數n,m,表示城市的數量和城市間現有的高鐵線路個數。其中n<=10,000, m<=100,000。接下來有m行,每行有空格隔開的兩個不同的字符串u,v,以及正整數C(C<=100,000),u,v的長度均小於20。表示u,v這兩座城市之間有高鐵線路,票價爲C。
  • 接下來有n行,每行有一個字符串city和一個非負整數x,代表在city這個城市中轉的最少花費爲x(元),包括打車費,住宿費(如果需要的話)等等
  • 接下來一行有一個正整數k表示詢問的個數,k<=2000
  • 接下來有k行,每行兩個字符串u,v代表出發地爲u,目的地爲v

輸出格式:

  • 第k組輸入,先輸出一行“Case #k:” (不輸出引號)
  • 每兩組輸入之間輸出兩行空行,增強可讀性,最後一組輸入的最後一個詢問後面輸出空行!
  • 對於同一組輸入中的第i個詢問,先輸出一行" query (i):"(不輸出引號,行首有2個空格),同時兩個詢問之間輸出一個空行,最後一個詢問後面輸出空行!
  • 對於每個詢問的每一行輸出,都要有4個空格的縮進。如果出發地或目的地在n個城市中沒有,輸出相關的提示,見樣例; 如果出發地和目的地在地圖上n個城市中都有,但是沒有高鐵線連通,也輸出相關提示,見樣例。如果有答案,輸出最少需要花費的數目,滿足最小花費的路線數量,以及給出一條具體的,中轉最少的路線。具體格式見樣例

樣例輸入

4

5 4
A B 1000
B C 2000
A C 355000
E D 4164
A 12
B 21
C 12
D 4
E 9
5
A C
A D
E A
A F
X Y

6 8
Beijing Shanghai 980
Beijing handan 400
Beijing Chongqing 442
Beijing Taiyuan 200
Taiyuan Chongqing 193
Taiyuan handan 150
handan Shanghai 499
Chongqing Shanghai 448
Beijing 113
Shanghai 120
Chongqing 89
Taiyuan 50
handan 80
Yangqu 45
5
Beijing Shanghai
Chongqing Yangqu
Taiyuan London
Tokyo Yangqu
Shanghai Beijing

3 1
London NewYork 803
London 549587
NewYork 779876
Paris 448676
4
NewYork London
London Paris
MianYang Taigu
London NewYork

5 4
A B 1000
B C 2000
A C 355000
E D 4164
A 12
B 21
C 12
D 4
E 9
5
A C
A D
E A
A F
X Y

樣例輸出:

Case #1:
  query (1): from A to C:
    The lest cost from A to C is: 3021.
    There is only one route which can satisfy the lest cost.
    The fewest number of transfer stations can be: 3.
    A->B->C.

  query (2): from A to D:
    Sorry,there are no way from A to D.

  query (3): from E to A:
    Sorry,there are no way from E to A.

  query (4): from A to F:
    F is not on this map.

  query (5): from X to Y:
    X and Y are not on this map.


Case #2:
  query (1): from Beijing to Shanghai:
    The lest cost from Beijing to Shanghai is: 979.
    There are 3 routes which can satisfy the lest cost.
    The fewest number of transfer stations can be: 3.
    Beijing->Chongqing->Shanghai.

  query (2): from Chongqing to Yangqu:
    Sorry,there are no way from Chongqing to Yangqu.

  query (3): from Taiyuan to London:
    London is not on this map.

  query (4): from Tokyo to Yangqu:
    Tokyo is not on this map.

  query (5): from Shanghai to Beijing:
    The lest cost from Shanghai to Beijing is: 979.
    There are 3 routes which can satisfy the lest cost.
    The fewest number of transfer stations can be: 3.
    Shanghai->handan->Beijing.


Case #3:
  query (1): from NewYork to London:
    The lest cost from NewYork to London is: 803.
    There is only one route which can satisfy the lest cost.
    The fewest number of transfer stations can be: 2.
    NewYork->London.

  query (2): from London to Paris:
    Sorry,there are no way from London to Paris.

  query (3): from MianYang to Taigu:
    MianYang and Taigu are not on this map.

  query (4): from London to NewYork:
    The lest cost from London to NewYork is: 803.
    There is only one route which can satisfy the lest cost.
    The fewest number of transfer stations can be: 2.
    London->NewYork.


Case #4:
  query (1): from A to C:
    The lest cost from A to C is: 3021.
    There is only one route which can satisfy the lest cost.
    The fewest number of transfer stations can be: 3.
    A->B->C.

  query (2): from A to D:
    Sorry,there are no way from A to D.

  query (3): from E to A:
    Sorry,there are no way from E to A.

  query (4): from A to F:
    F is not on this map.

  query (5): from X to Y:
    X and Y are not on this map.

AC愉快~

xzc
2020/2/11 9:52


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章