假定已經(jīng)有許多應(yīng)用采用了程序1 - 1 5中所定義的C u r r e n c y類,現(xiàn)在我們想要對C u r r e n c y類
的描述進(jìn)行修改,使其應(yīng)用頻率最高的兩個函數(shù)A d d和I n c r e m e n t可以運(yùn)行得更快,從而提高應(yīng)
用程序的執(zhí)行速度。由于用戶僅能通過p u b l i c部分所提供的接口與C u r r e n c y類進(jìn)行交互,
HDOJ ACM
input:The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case begins with a line containing an integer N , 1<=N<=200 , that represents the number of tables to move. Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in the same manner as above.
Input
The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. The first line of each case contains N, and the second line contains N integers giving the time for each people to cross the river. Each case is preceded by a blank line. There won t be more than 1000 people and nobody takes more than 100 seconds to cross.
Output
For each test case, print a line containing the total number of seconds required for all the N people to cross the river.
Sample Input
1
4
1 2 5 10
Sample Output
17