結果
問題 | No.2301 Namorientation |
ユーザー |
![]() |
提出日時 | 2023-05-16 14:41:51 |
言語 | Ruby (3.4.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,241 bytes |
コンパイル時間 | 255 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 89,664 KB |
最終ジャッジ日時 | 2024-12-14 15:08:09 |
合計ジャッジ時間 | 30,428 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 RE * 3 |
コンパイルメッセージ
Main.rb:37: warning: assigned but unused variable - f Syntax OK
ソースコード
N = gets.to_iO = Hash.new { |h, k| h[k] = {} }E = Array.new(N + 1) { [] }OE = []N.times doa, b = gets.split.map(&:to_i)E[a] << bE[b] << aOE << [a, b]enddef find_loop(v, par, path, visited)if visited[v]from = path.index(v)return [path[from..], true]endvisited[v] = truepath << vE[v].each do |u|next if u == parres, found = find_loop(u, v, path, visited)if foundreturn [res, found]endendpath.popendpath = []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.sizen.times do |i|a = loop_path[i]b = loop_path[(i + 1) % n]queue << avisited[a] = trueO[a][b] = 1enduntil queue.empty?v = queue.shiftE[v].each do |u|next if visited[u]visited[u] = trueO[v][u] = 1queue << uendend1.upto(N) do |n|next if visited[n]queue << nuntil queue.empty?v = queue.shiftE[v].each do |u|next if visited[u]visited[u] = trueO[v][u] = 1endendendcounter = Hash.new(0)OE.each do |a, b|if O[a][b]counter[b] += 1puts '<-'elsecounter[a] += 1puts '->'endend