結果
| 問題 | No.317 辺の追加 |
| コンテスト | |
| ユーザー |
小指が強い人
|
| 提出日時 | 2015-12-11 21:47:12 |
| 言語 | Ruby (3.4.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,106 bytes |
| 記録 | |
| コンパイル時間 | 44 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 37,120 KB |
| 最終ジャッジ日時 | 2024-09-15 08:25:06 |
| 合計ジャッジ時間 | 18,327 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 3 WA * 18 RE * 17 |
コンパイルメッセージ
Syntax OK
ソースコード
# 辺の追加
def solve(i, u, k)
return if i >= $r.length
ur = u + $r[i]
return if $memo[ur - 1] >= 0
$memo[ur - 1] = k
solve(i + 1, u, k)
solve(i + 1, ur, k + 1)
end
$n, m = gets.split.map(&:to_i)
#n = 2 * 10 ** 5
#m = 2 * 10 ** 5
a = Hash.new{|h, k| h[k] = Array.new}
b = Array.new($n, false)
#n.times do |i|
# a[2 * i + 1].push(2 * i + 2)
# a[2 * i + 2].push(2 * i + 1)
#end
m.times do |i|
s = gets.split.map(&:to_i)
next if s[0] == s[1]
a[s[0]].push(s[1])
a[s[1]].push(s[0])
end
$r = Array.new
$memo = Array.new($n, -1)
stack = Array.new(m + 10)
$n.times do |i|
i += 1
next if b[i]
top = 1
bottom = 0
stack[0] = i
count = 1
while bottom < top do
j = stack[top - 1]
if !a.has_key?(j)
top -= 1
next
end
b[j] = true
a[j].each do |x|
next if b[x]
b[x] = true
stack[top] = x
top += 1
count += 1
end
bottom += 1
end
$r.push(count)
end
$r.sort!{|a, b| b <=> a}
solve(0, 0, 0)
puts $memo
小指が強い人