1. 程式人生 > >2017 ACM 區域賽青島站(現場賽) K Our Journey of Xian Ends

2017 ACM 區域賽青島站(現場賽) K Our Journey of Xian Ends

Life is a journey, and the road we travel has twists and turns, which sometimes lead us to unexpected places and unexpected people. Now our journey of Xian ends. To be carefully considered are the following questions.

A few months later in Qingdao, an essential ACM competition had been scheduled. But before the competition, we need to attend a wedding in Shanghai. And after the competition, we will leave the country from Shanghai, so Pudong International Airport (Pudong in short) is the end of our tour.

Here we have some vital information and missions we have to accomplish.

We have a VIP card of CNAC. For each airport we can enjoy the special VIP services in the departure floor and the arrival floor once respectively. For the pleasure of traveling, it is intolerant without VIP services. That is say that for each airport we can leave from it only once, but without regard to the last flight leaving the country from Pudong, Shanghai. Meanwhile, for each airport we can arrive at it only once.

All as we know, Shanghai has two airports, Hongqiao Airport (Hongqiao in short) and Pudong. Arriving at one and then leaving from another one is a spurned thing. But fortunately there is a nice and evil compensation service. Having a pair of transfer records between Hongqiao and Pudong in both directions, we can obtain a sensible compensation. Actually, we only consider planes in our tour, with the only exception in Shanghai. The exception is that we can arrive and leave Shanghai at different airports. However, if we decide so the compensation described above is necessary. Before the end of our tour, we will pass through Shanghai twice, once for the wedding and another time for the final departure. If we want to obtain the compensation, in the first time we must transfer from Pudong to Hongqiao, and in the second time we will transfer from Hongqiao to Pudong.

Similar transfers between airports in other city are not allowed. If we arrived at a city, we would not go to an airport in an adjacent city by car, bus or interurban railway as well.

Now, all available flights between airports are known. We have plenty of time yet. So we do not have any restriction about the number of times. What we require is the smallest total cost of flights throughout the whole tour.

Here we go.

Input

There are several test cases. The first line of input contains an integer t (1 ≤ t ≤ 160) which is the total number of test cases. For each test case, the first line contains an integer m (m ≤ 10000) which is the number of known flights. Each of the following m lines describes a flight which contains two string indicating the names of two airports and an integer between 1 and 255 indicating the cost. The flight connects two given airports and it is bidirectional. The name of each airport is an non-empty string with English letters that are no longer than 10. We use “Xian” to present the only airport in Xian, and use “Qingdao” to present the only airport in Qingdao. The airports in Shanghai are described as “Hongqiao” and “Pudong” respectively.

Output

For each test case, output the smallest total cost, or output −1 if it is impossible.

相關推薦

2017 ACM 區域青島現場 K Our Journey of Xian Ends

Life is a journey, and the road we travel has twists and turns, which sometimes lead us to unexpected places and unexpected people. Now our journey of Xia

2017 icpc 青島 K. Our Journey of Xian Ends 最小費用流

K. Our Journey of Xian Ends 題意:這英文題真是比六級閱讀還難讀,給你一個無向圖,求西安-->上海-->青島-->上海的最短路,每個城市有一個機場,但是上海有兩個機場 虹橋機場和浦東機場,上海這兩個機場可以互達(你可以從西安到浦東,然後再從虹橋到青

2017 icpc 青島 K. Our Journey of Xian Ends 最小費用流

題意:這英文題真是比六級閱讀還難讀,給你一個無向圖,求西安-->上海-->青島-->上海的最短路,每個城市有一個機場,但是上海有兩個機場 虹橋機場和浦東機場,上海這兩個機場可以互達(你可以從西安到浦東,然後再從虹橋到青島,距離為0),每個機場只能下飛機和

2017 ACM-ICPC 亞洲區烏魯木齊賽區網路 J.Our Journey of Dalian Ends【最小費用最大流】

Life is a journey, and the road we travel has twists and turns, which sometimes lead us to unexpected places and unexpected people. Now our journey of Dal

計蒜客-2017 ACM-ICPC 亞洲區(烏魯木齊賽區)網路J題Our Journey of Dalian Ends (最小費用最大流)

題意: 給定若干個城市,出發點為大連,目的地為西安,但是要求中途必須經過上海,並且圖中每個城市只能經過一次,給出m條路(雙向道路),走第i條路需要wi代價,求所有滿足要求的方案中花費的最小代價,如果沒有滿足的方案,輸出-1。 思路: 相當於求從大連到上海加上西安到上海花費的

2017烏魯木齊網絡 J題 Our Journey of Dalian Ends ( 最小費用最大流 )

增廣路 ali += ase turn src eof weight flow 題目鏈接 題意 : 給出一副圖,大連是起點,終點是西安,要求你求出從起點到終點且經過中轉點上海的最小花費是多少? 分析 : 最短路是最小費用最大流的一個特例,所以有些包含中轉限制或者經過點

ACM ICPC 烏魯木齊網路 J. Our Journey of Dalian Ends

Life is a journey, and the road we travel has twists and turns, which sometimes lead us to unexpected places and unexpected people. Now o

2017 ACM區域現場 青島 E polya計數

amp mod 循環 等價 img cout es2017 範圍 知乎 題目鏈接(暫無) 吐槽:這場比賽感覺對我感覺還算友好,雖然Q群知乎上命題方已經被噴死了,C語言上機題還有字符串題有大腿隊友輕松搞定,網絡流恰是我能想出來的,E本來也應該是在能力範圍內,不過因為之前沒寫過

2016 ACM/ICPC亞洲區青島現場部分題解

多少 條件 技術 留下 tin tdi scanf .get max 摘要   本文主要列舉並求解了2016 ACM/ICPC亞洲區青島站現場賽的部分真題,著重介紹了各個題目的解題思路,結合詳細的AC代碼,意在熟悉青島賽區的出題策略,以備戰2018青島站現場賽。 HD

2018 ACM-ICPC 亞洲區域青島 C-Flippy Sequence計數

  思路來源 https://blog.csdn.net/Game_Acm/article/details/83745455 題意 給兩個01串A串和B串,在A串中可以進行區間翻轉操作,可以使得一個區間內所有的0變成1,所有的1變成0,求恰好翻轉兩次使得A

2017 ACM區域(南寧) 參賽流水賬

字符 暴力 through abc 參數 ble 搜索 推公式 stay day0:  早上四點起床趕飛機,還好沒有吵醒室友導致被打死。本來想在飛機上準備一下下周的小測,結果飛機一點都不平穩,只能全程和隊友吹逼聊天。下午在賓館裏和johann通關了一部合金彈頭,重溫了童年的

2018 ACM-ICPC 亞洲區域青島 J-Books(貪心)

  思路來源 https://blog.csdn.net/Game_Acm/article/details/83745455 題意 有n本書從第1本書開始買,對於每本書能買則買,求恰好買m本書的最大攜帶錢數, 如果攜帶錢數無上限(即存在INF的情況能買下所有

2018 ACM-ICPC 亞洲區域青島 E - Plants vs. Zombies(二分)

題意 有n個植物,m次移動1格的機會, 以下n個數a1-an,代表每一次澆水(其實就是訪問),該處的植物會增加防禦值ai,初始防禦值di=0 n個植物分別在座標軸1,…,n的位置,澆水機的位置初始在0, 座標軸無限長,移動1格會耗費1次機會, 從0移動到1上時,

2016ACM/ICPC亞洲區青島區域練習

A - Relic Discovery Recently, paleoanthropologists have found historical remains on an island in the Atlantic Ocean. The most inspiring

2018 ACM-ICPC 亞洲區域青島 E

題意 有n個植物,m次移動1格的機會, 以下n個數a1-an,代表每一次澆水(其實就是訪問),該處的植物會增加防禦值ai,初始防禦值di=0 n個植物分別在座標軸1,…,n的位置,澆水機的位置初始在0, 座標軸無限長,移動1格會耗費1次機會, 從0移動到

2018 icpc 亞洲區域青島總結

       第一次參加區域賽,目標保銅爭銀,失誤挺大,遺憾只完成了前面一半。        第一次去青島,然後吃了幾天石油大學的食堂,沒有一次把飯吃完,沒有辣椒真吃不慣。到了熱身賽

ACM 2018 北京區域 I - Palindromes 找規律

HihoCoder - 1878 題目大意:        給出k,讓求出第k個迴文數(k的“長度”不超過1e5) 題解:        真是一道給人警醒的題目 &

2018年icpc亞洲區域青島 賽後總結

上個星期結束了青島站的比賽,也意味著我的ACM生涯接近了尾聲。過程也算是跌跌撞撞,最後4題銅收尾。 可能現在回想我的ACM生涯會有點早,那就等我徹底結束比賽的時候再寫部落格來緬懷吧。 不想仔細說題了,大概說一下榜單情況吧。三題手速快銅中下,4題手速快銀中下,6題慢銀首,大

2016年青島區域 Coding Contest費用流

題意:有n個區域,m條邊連線這些區域,這些邊是單向的。現在給出每個區域有多少個選手,多少個午餐。有的區域的選手沒有午餐,所以他們只能去其他區域找午餐。在給定的單向邊上面,有一個流量限制,不能通過超過這個數量的人。而且這些邊上面有網線,只有一個人通過不會對網線有影響,但是有多

ACM總結——2017ACM-ICPC北京賽區現場總結

合並 number 啊啊啊啊啊啊啊啊 greate less striped 模板 strong wine   現在距離比賽結束已經過了一個多星期了,也是終於有時間寫下心得了。回來就是被壓著做項目,也是夠夠的。   這次比賽一樣是我和兩個學弟(雖然是學弟,但我的實力才是最