結果
| 問題 |
No.241 出席番号(1)
|
| ユーザー |
|
| 提出日時 | 2017-03-20 02:11:32 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,016 bytes |
| コンパイル時間 | 1,598 ms |
| コンパイル使用メモリ | 169,236 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-30 21:40:35 |
| 合計ジャッジ時間 | 2,930 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int MAX_V = 100;
int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];
void add_edge(int u, int v) {
G[u].push_back(v);
G[v].push_back(u);
}
bool dfs(int v) {
used[v] = true;
for (int i = 0; i < G[v].size(); i++) {
int u = G[v][i], w = match[u];
if (w < 0 || !used[w] && dfs(w)) {
match[v] = u;
match[u] = v;
return true;
}
}
return false;
}
int bipartite_matching() {
int res = 0;
memset(match, -1, sizeof(match));
for (int v = 0; v < V; v++) {
if (match[v] < 0) {
memset(used, 0, sizeof(used));
if (dfs(v)) res++;
}
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
V = 2 * n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
for (int j = 0; j < n; j++) {
if (j == a) continue;
add_edge(i, n + j);
}
}
if (bipartite_matching() != n) {
cout << -1 << endl;
} else {
for (int i = 0; i < n; i++) {
cout << match[i] - n << endl;
}
}
return 0;
}