結果

問題 No.1254 補強への架け橋
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2021-02-16 22:00:38
言語 Ruby
(3.3.0)
結果
AC  
実行時間 587 ms / 2,000 ms
コード長 708 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 11,524 KB
実行使用メモリ 38,456 KB
最終ジャッジ日時 2023-10-11 12:12:42
合計ジャッジ時間 35,241 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
15,136 KB
testcase_01 AC 86 ms
15,320 KB
testcase_02 AC 82 ms
15,096 KB
testcase_03 AC 83 ms
15,204 KB
testcase_04 AC 83 ms
15,064 KB
testcase_05 AC 83 ms
15,088 KB
testcase_06 AC 83 ms
15,276 KB
testcase_07 AC 87 ms
15,112 KB
testcase_08 AC 83 ms
15,060 KB
testcase_09 AC 85 ms
15,148 KB
testcase_10 AC 85 ms
15,128 KB
testcase_11 AC 85 ms
15,280 KB
testcase_12 AC 84 ms
15,292 KB
testcase_13 AC 84 ms
15,288 KB
testcase_14 AC 85 ms
15,344 KB
testcase_15 AC 84 ms
15,064 KB
testcase_16 AC 86 ms
15,280 KB
testcase_17 AC 85 ms
15,048 KB
testcase_18 AC 83 ms
15,052 KB
testcase_19 AC 83 ms
15,048 KB
testcase_20 AC 84 ms
15,180 KB
testcase_21 AC 84 ms
15,052 KB
testcase_22 AC 83 ms
15,336 KB
testcase_23 AC 83 ms
15,272 KB
testcase_24 AC 84 ms
15,064 KB
testcase_25 AC 84 ms
15,288 KB
testcase_26 AC 85 ms
15,108 KB
testcase_27 AC 85 ms
15,292 KB
testcase_28 AC 84 ms
15,092 KB
testcase_29 AC 84 ms
15,360 KB
testcase_30 AC 86 ms
15,264 KB
testcase_31 AC 85 ms
15,056 KB
testcase_32 AC 85 ms
15,096 KB
testcase_33 AC 87 ms
15,328 KB
testcase_34 AC 85 ms
15,308 KB
testcase_35 AC 84 ms
15,136 KB
testcase_36 AC 85 ms
15,132 KB
testcase_37 AC 84 ms
15,276 KB
testcase_38 AC 84 ms
15,312 KB
testcase_39 AC 84 ms
15,056 KB
testcase_40 AC 84 ms
15,320 KB
testcase_41 AC 84 ms
15,128 KB
testcase_42 AC 84 ms
15,060 KB
testcase_43 AC 87 ms
15,168 KB
testcase_44 AC 85 ms
15,088 KB
testcase_45 AC 86 ms
15,064 KB
testcase_46 AC 87 ms
15,128 KB
testcase_47 AC 86 ms
15,208 KB
testcase_48 AC 86 ms
15,052 KB
testcase_49 AC 85 ms
15,132 KB
testcase_50 AC 88 ms
15,152 KB
testcase_51 AC 87 ms
15,284 KB
testcase_52 AC 87 ms
15,152 KB
testcase_53 AC 87 ms
15,284 KB
testcase_54 AC 87 ms
15,092 KB
testcase_55 AC 86 ms
15,060 KB
testcase_56 AC 87 ms
15,152 KB
testcase_57 AC 89 ms
15,372 KB
testcase_58 AC 88 ms
15,048 KB
testcase_59 AC 88 ms
15,288 KB
testcase_60 AC 87 ms
15,148 KB
testcase_61 AC 88 ms
15,056 KB
testcase_62 AC 88 ms
15,136 KB
testcase_63 AC 118 ms
16,480 KB
testcase_64 AC 92 ms
15,428 KB
testcase_65 AC 104 ms
15,932 KB
testcase_66 AC 102 ms
15,612 KB
testcase_67 AC 93 ms
15,244 KB
testcase_68 AC 102 ms
15,832 KB
testcase_69 AC 108 ms
16,328 KB
testcase_70 AC 94 ms
15,500 KB
testcase_71 AC 90 ms
15,324 KB
testcase_72 AC 106 ms
16,060 KB
testcase_73 AC 92 ms
15,564 KB
testcase_74 AC 106 ms
16,204 KB
testcase_75 AC 99 ms
15,788 KB
testcase_76 AC 85 ms
15,428 KB
testcase_77 AC 97 ms
15,832 KB
testcase_78 AC 111 ms
16,528 KB
testcase_79 AC 110 ms
16,460 KB
testcase_80 AC 109 ms
16,100 KB
testcase_81 AC 113 ms
16,452 KB
testcase_82 AC 108 ms
16,376 KB
testcase_83 AC 495 ms
34,104 KB
testcase_84 AC 449 ms
33,844 KB
testcase_85 AC 313 ms
25,908 KB
testcase_86 AC 391 ms
32,468 KB
testcase_87 AC 421 ms
33,140 KB
testcase_88 AC 124 ms
17,784 KB
testcase_89 AC 476 ms
34,312 KB
testcase_90 AC 301 ms
26,864 KB
testcase_91 AC 251 ms
25,360 KB
testcase_92 AC 176 ms
20,400 KB
testcase_93 AC 415 ms
31,544 KB
testcase_94 AC 311 ms
30,052 KB
testcase_95 AC 350 ms
29,968 KB
testcase_96 AC 413 ms
33,644 KB
testcase_97 AC 226 ms
23,832 KB
testcase_98 AC 455 ms
33,776 KB
testcase_99 AC 286 ms
25,776 KB
testcase_100 AC 426 ms
34,240 KB
testcase_101 AC 161 ms
19,316 KB
testcase_102 AC 124 ms
17,472 KB
testcase_103 AC 178 ms
20,312 KB
testcase_104 AC 218 ms
21,812 KB
testcase_105 AC 391 ms
31,496 KB
testcase_106 AC 253 ms
25,020 KB
testcase_107 AC 427 ms
34,080 KB
testcase_108 AC 469 ms
34,176 KB
testcase_109 AC 377 ms
31,452 KB
testcase_110 AC 361 ms
29,752 KB
testcase_111 AC 363 ms
31,160 KB
testcase_112 AC 202 ms
21,508 KB
testcase_113 AC 334 ms
28,876 KB
testcase_114 AC 249 ms
24,648 KB
testcase_115 AC 135 ms
17,972 KB
testcase_116 AC 253 ms
25,428 KB
testcase_117 AC 201 ms
21,200 KB
testcase_118 AC 469 ms
33,548 KB
testcase_119 AC 271 ms
25,732 KB
testcase_120 AC 429 ms
32,952 KB
testcase_121 AC 182 ms
20,376 KB
testcase_122 AC 279 ms
25,004 KB
testcase_123 AC 83 ms
15,284 KB
testcase_124 AC 586 ms
38,404 KB
testcase_125 AC 587 ms
38,456 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

Edge = Struct.new(:to, :id)
N = gets.to_i
G = Array.new(N + 1){ [] }
(1 .. N).each do |i|
  a,b = gets.split.map(&:to_i)
  G[a] << Edge.new(b, i)
  G[b] << Edge.new(a, i)
end

active = Array.new(N + 1)
parent = Array.new(N + 1)
depth = Array.new(N + 1)

active[N] = G[N].size
parent[N] = N
depth[N] = 0
u = N
loop do
  j = (active[u] -= 1)
  e = G[u][j]
  v = e.to
  
  if j < 0
    u = parent[u]
  elsif !active[v]
    active[v] = G[v].size
    depth[v] = depth[u] + 1
    parent[v] = u
    u = v
  elsif v != parent[u]
    cycle = [e.id]
    w = v
    until w == u
      cycle << G[w][active[w]].id
      w = G[w][active[w]].to
    end
    
    puts cycle.size
    puts cycle.join(" ")
    break
  end
end
0