結果
| 問題 |
No.241 出席番号(1)
|
| ユーザー |
femto
|
| 提出日時 | 2016-09-26 00:05:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,334 bytes |
| コンパイル時間 | 826 ms |
| コンパイル使用メモリ | 90,192 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-30 21:40:06 |
| 合計ジャッジ時間 | 2,018 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;
struct BipartiteMatching {
int V;
vector<vector<bool> > G;
vector<int> match;
vector<bool> used;
BipartiteMatching(int v) {
V = v;
G = vector<vector<bool> >(v, vector<bool>(v));
match = vector<int>(v);
used = vector<bool>(v);
}
void add_edge(int v, int u) {
G[v][u] = G[u][v] = true;
}
bool dfs(int v) {
used[v] = true;
for(int i = 0; i < V; i++) {
if(!G[v][i]) continue;
int u = i, w = match[u];
if(w < 0 || (!used[w] && dfs(w))) {
match[v] = u;
match[u] = v;
return true;
}
}
return false;
}
int calc() {
int res = 0;
fill(match.begin(), match.end(), -1);
for(int v = 0; v < V; v++) {
if(match[v] < 0) {
fill(used.begin(), used.end(), false);
if(dfs(v)) {
res++;
}
}
}
return res;
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
BipartiteMatching bp(2 * 50);
for(int i = 0; i < N; i++) {
int a;
cin >> a;
for(int j = 0; j < N; j++) {
if(a == j) continue;
bp.add_edge(i, 50 + j);
}
}
if(bp.calc() != N) {
cout << -1 << endl;
}
else {
for(int i = 0; i < N; i++) {
cout << bp.match[i] - 50 << endl;
}
}
}
femto