結果

問題 No.2301 Namorientation
ユーザー simansiman
提出日時 2023-05-16 15:00:07
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,786 ms / 3,000 ms
コード長 1,500 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 11,328 KB
実行使用メモリ 359,496 KB
最終ジャッジ日時 2023-08-21 06:04:53
合計ジャッジ時間 34,708 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 159 ms
15,376 KB
testcase_01 AC 161 ms
15,276 KB
testcase_02 AC 159 ms
15,420 KB
testcase_03 AC 160 ms
15,388 KB
testcase_04 AC 158 ms
15,356 KB
testcase_05 AC 164 ms
15,320 KB
testcase_06 AC 160 ms
15,232 KB
testcase_07 AC 158 ms
15,328 KB
testcase_08 AC 159 ms
15,436 KB
testcase_09 AC 160 ms
15,352 KB
testcase_10 AC 160 ms
15,284 KB
testcase_11 AC 161 ms
15,316 KB
testcase_12 AC 819 ms
69,136 KB
testcase_13 AC 731 ms
60,596 KB
testcase_14 AC 1,230 ms
101,820 KB
testcase_15 AC 873 ms
73,180 KB
testcase_16 AC 1,113 ms
87,068 KB
testcase_17 AC 821 ms
69,080 KB
testcase_18 AC 1,071 ms
87,808 KB
testcase_19 AC 689 ms
58,616 KB
testcase_20 AC 1,117 ms
88,364 KB
testcase_21 AC 872 ms
68,064 KB
testcase_22 AC 1,785 ms
359,496 KB
testcase_23 AC 1,786 ms
358,496 KB
testcase_24 AC 1,279 ms
310,944 KB
testcase_25 AC 847 ms
58,424 KB
testcase_26 AC 1,065 ms
64,368 KB
testcase_27 AC 1,300 ms
101,340 KB
testcase_28 AC 1,323 ms
101,272 KB
testcase_29 AC 1,292 ms
101,416 KB
testcase_30 AC 1,307 ms
101,496 KB
testcase_31 AC 1,316 ms
101,456 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:40: warning: assigned but unused variable - f
Syntax OK

ソースコード

diff #

if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'1000000000'}, '/usr/bin/ruby', $0)
else
  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
end
0