結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
15,080 KB
testcase_01 AC 145 ms
15,532 KB
testcase_02 AC 81 ms
15,064 KB
testcase_03 AC 85 ms
15,304 KB
testcase_04 AC 82 ms
15,256 KB
testcase_05 AC 109 ms
15,384 KB
testcase_06 AC 156 ms
15,336 KB
testcase_07 AC 81 ms
15,304 KB
testcase_08 AC 80 ms
15,124 KB
testcase_09 AC 83 ms
15,180 KB
testcase_10 AC 82 ms
15,036 KB
testcase_11 AC 83 ms
15,356 KB
testcase_12 AC 82 ms
15,132 KB
testcase_13 AC 81 ms
15,304 KB
testcase_14 AC 126 ms
15,420 KB
testcase_15 AC 93 ms
15,108 KB
testcase_16 AC 127 ms
15,420 KB
testcase_17 AC 83 ms
15,152 KB
testcase_18 AC 85 ms
15,344 KB
testcase_19 AC 88 ms
15,128 KB
testcase_20 AC 129 ms
15,340 KB
testcase_21 AC 154 ms
15,312 KB
testcase_22 AC 167 ms
15,400 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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