結果
問題 | No.2301 Namorientation |
ユーザー | siman |
提出日時 | 2023-05-16 14:41:51 |
言語 | Ruby (3.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,241 bytes |
コンパイル時間 | 169 ms |
コンパイル使用メモリ | 11,288 KB |
実行使用メモリ | 104,328 KB |
最終ジャッジ日時 | 2023-08-21 05:54:28 |
合計ジャッジ時間 | 28,747 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 84 ms
15,304 KB |
testcase_01 | AC | 82 ms
15,188 KB |
testcase_02 | AC | 83 ms
15,292 KB |
testcase_03 | AC | 82 ms
15,264 KB |
testcase_04 | AC | 83 ms
15,124 KB |
testcase_05 | AC | 82 ms
15,168 KB |
testcase_06 | AC | 82 ms
15,044 KB |
testcase_07 | AC | 82 ms
15,140 KB |
testcase_08 | AC | 82 ms
15,184 KB |
testcase_09 | AC | 82 ms
15,140 KB |
testcase_10 | AC | 83 ms
15,104 KB |
testcase_11 | AC | 82 ms
15,256 KB |
testcase_12 | AC | 755 ms
69,060 KB |
testcase_13 | AC | 661 ms
60,616 KB |
testcase_14 | AC | 1,190 ms
101,796 KB |
testcase_15 | AC | 825 ms
73,340 KB |
testcase_16 | AC | 1,087 ms
86,624 KB |
testcase_17 | AC | 781 ms
69,484 KB |
testcase_18 | AC | 1,018 ms
87,408 KB |
testcase_19 | AC | 640 ms
58,832 KB |
testcase_20 | AC | 1,091 ms
87,656 KB |
testcase_21 | AC | 812 ms
68,008 KB |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | AC | 787 ms
56,456 KB |
testcase_26 | AC | 985 ms
64,540 KB |
testcase_27 | AC | 1,204 ms
101,120 KB |
testcase_28 | AC | 1,258 ms
101,488 KB |
testcase_29 | AC | 1,246 ms
101,408 KB |
testcase_30 | AC | 1,233 ms
101,552 KB |
testcase_31 | AC | 1,238 ms
104,328 KB |
コンパイルメッセージ
Main.rb:37: warning: assigned but unused variable - f Syntax OK
ソースコード
N = gets.to_i O = Hash.new { |h, k| h[k] = {} } E = Array.new(N + 1) { [] } OE = [] N.times do a, b = gets.split.map(&:to_i) E[a] << b E[b] << a OE << [a, b] end def find_loop(v, par, path, visited) if visited[v] from = path.index(v) return [path[from..], true] end visited[v] = true path << v E[v].each do |u| next if u == par res, found = find_loop(u, v, path, visited) if found return [res, found] end end path.pop end path = [] visited = Array.new(N + 1, false) loop_path, f = find_loop(1, nil, path, visited) queue = [] visited = Array.new(N + 1, false) n = loop_path.size n.times do |i| a = loop_path[i] b = loop_path[(i + 1) % n] queue << a visited[a] = true O[a][b] = 1 end until queue.empty? v = queue.shift E[v].each do |u| next if visited[u] visited[u] = true O[v][u] = 1 queue << u end end 1.upto(N) do |n| next if visited[n] queue << n until queue.empty? v = queue.shift E[v].each do |u| next if visited[u] visited[u] = true O[v][u] = 1 end end end counter = Hash.new(0) OE.each do |a, b| if O[a][b] counter[b] += 1 puts '<-' else counter[a] += 1 puts '->' end end