結果
| 問題 |
No.241 出席番号(1)
|
| コンテスト | |
| ユーザー |
TANIGUCHI Kousuke
|
| 提出日時 | 2015-09-21 07:43:09 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 92 ms / 2,000 ms |
| コード長 | 908 bytes |
| コンパイル時間 | 141 ms |
| コンパイル使用メモリ | 7,680 KB |
| 実行使用メモリ | 12,544 KB |
| 最終ジャッジ日時 | 2024-11-30 21:33:56 |
| 合計ジャッジ時間 | 3,839 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
コンパイルメッセージ
Main.rb:48: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
# Here your code !
G = []
Vertex = Struct.new(:value,:edges)
def G.add_vert(value)
G.push(Vertex.new(value,[]))
G.size - 1
end
def G.add_edge(u,v)
G[u].edges.push(v)
G[v].edges.push(u)
end
def G.matching
G.size.times.each_with_object({}) do |v,matched|
find_path(v,matched) unless matched[v]
end
end
def G.find_path(v,matched,visited = {})
visited[v] = true
self[v].edges.find do |u|
w = matched[u]
if !w || (!visited[w] && find_path(w,matched,visited))
matched[v] = u
matched[u] = v
end
end
end
n = gets.to_i
U = n.times.map {|u| G.add_vert(u)}
V = n.times.map {|v| G.add_vert(v)}
A = n.times.map { gets.to_i }
n.times do |u|
n.times do |v|
G.add_edge(U[u],V[v]) unless v == A[u]
end
end
m = G.matching
if m.size == n * 2
puts U.map {|u| m[u]}.map {|v| G[v].value }
else
puts -1
end
TANIGUCHI Kousuke