結果
| 問題 |
No.1640 簡単な色塗り
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-29 14:40:39 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 705 bytes |
| コンパイル時間 | 39 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 110,620 KB |
| 最終ジャッジ日時 | 2024-07-02 11:31:09 |
| 合計ジャッジ時間 | 4,663 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 TLE * 1 -- * 51 |
コンパイルメッセージ
Syntax OK
ソースコード
N = gets.to_i
$G = Array.new(N*2) {Array.new}
$match = Array.new(N*2, -1)
def add_edge(u, v)
$G[u] << v
$G[v] << u
end
def dfs(v)
$used[v] = true
$G[v].each {|u|
w = $match[u]
if w < 0 or (not $used[w] and dfs(w)) then
$match[v] = u
$match[u] = v
return true
end
}
return false
end
def bipartite_matching
res = 0
0.upto(2*N-1) {|v|
if $match[v] < 0 then
$used = Array.new(N*2, false)
if dfs(v) then
res += 1
end
end
}
return res
end
0.upto(N-1) { |i|
a, b = gets.split(" ").map{|s| s.to_i}
add_edge(i, a + N - 1)
add_edge(i, b + N - 1)
}
n = bipartite_matching
if n == N then
puts "Yes"
0.upto(N-1) {|i|
puts $match[i] - N + 1
}
else
puts "No"
end