結果
問題 |
No.812 Change of Class
|
ユーザー |
|
提出日時 | 2019-04-12 22:25:22 |
言語 | Ruby (3.4.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 541 bytes |
コンパイル時間 | 470 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 44,160 KB |
最終ジャッジ日時 | 2024-06-12 19:17:57 |
合計ジャッジ時間 | 21,101 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 WA * 23 RE * 25 |
コンパイルメッセージ
Syntax OK
ソースコード
N, M = gets.split.map &:to_i edges = N.times.map{ [] } M.times{ a, b = gets.split.map &:to_i edges[a-1] << b-1 edges[b-1] << a-1 } Q = gets.to_i Q.times{ a = gets.to_i-1 max_depth = 0 visited = [false] * N f = -> from, depth { return if visited[from] visited[from] = true max_depth = depth if depth > max_depth edges[from].each{|to| f[to, depth + 1] } } if edges[a].empty? puts "0 0" else f[a, 0] puts "#{visited.count(true) - 1} #{max_depth < 2 ? 0 : (max_depth + 1) / 2}" end }