結果

問題 No.119 旅行のツアーの問題
ユーザー 👑 hos.lyrichos.lyric
提出日時 2015-02-18 06:32:31
言語 Ruby
(3.3.0)
結果
AC  
実行時間 181 ms / 5,000 ms
コード長 394 bytes
コンパイル時間 62 ms
コンパイル使用メモリ 11,456 KB
実行使用メモリ 15,888 KB
最終ジャッジ日時 2023-08-23 09:15:17
合計ジャッジ時間 3,701 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
15,532 KB
testcase_01 AC 158 ms
15,888 KB
testcase_02 AC 81 ms
15,128 KB
testcase_03 AC 80 ms
15,140 KB
testcase_04 AC 80 ms
15,340 KB
testcase_05 AC 115 ms
15,524 KB
testcase_06 AC 174 ms
15,704 KB
testcase_07 AC 79 ms
15,316 KB
testcase_08 AC 79 ms
15,132 KB
testcase_09 AC 80 ms
15,152 KB
testcase_10 AC 81 ms
15,296 KB
testcase_11 AC 80 ms
15,060 KB
testcase_12 AC 80 ms
15,184 KB
testcase_13 AC 81 ms
15,304 KB
testcase_14 AC 134 ms
15,600 KB
testcase_15 AC 93 ms
15,256 KB
testcase_16 AC 140 ms
15,776 KB
testcase_17 AC 84 ms
15,372 KB
testcase_18 AC 87 ms
15,380 KB
testcase_19 AC 91 ms
15,052 KB
testcase_20 AC 140 ms
15,352 KB
testcase_21 AC 167 ms
15,864 KB
testcase_22 AC 181 ms
15,744 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

z=9999
n=gets.to_i
g=(1..l=n*5).map{[0]*l}
a=0
(1..n).map{|u|b,c=gets.split;a+=g[1][2+u]=b.to_i;a+=g[r=2+n+u][2]=c.to_i;g[2+u][r]=z}
gets.to_i.times{d,e=gets.split;g[3+d.to_i][3+n+e.to_i]=z}
(q=[1]
p=[0]*l
(u=q.shift;l.times{|v|(p[v]=u;q<<v)if p[v]<1&&g[u][v]>0})while q!=[]
break if p[v=w=2]<1
m=z
(m=[m,g[u=p[v]][v]].min;v=u)while v>1
a-=m
(g[u=p[w]][w]-=m;g[w][w=u]+=m)while w>1)until !n
p a
0