結果
| 問題 |
No.241 出席番号(1)
|
| ユーザー |
maine_honzuki
|
| 提出日時 | 2021-05-02 22:19:56 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 881 bytes |
| コンパイル時間 | 4,182 ms |
| コンパイル使用メモリ | 259,188 KB |
| 最終ジャッジ日時 | 2025-01-21 06:04:29 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
//https://ncode.syosetu.com/n4830bu/241/
#include "atcoder/all"
using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
mf_graph<int> maine(N * 2 + 2);
int s = N * 2, t = N * 2 + 1;
for (int i = 0; i < N; i++) {
maine.add_edge(s, i, 1);
maine.add_edge(i + N, t, 1);
for (int j = 0; j < N; j++) {
if (j != A[i])
maine.add_edge(i, j + N, 1);
}
}
if (maine.flow(s, t) == N) {
vector<int> ans(N);
for (auto&& edge : maine.edges()) {
if (edge.from < N && edge.flow == 1)
ans[edge.from] = edge.to - N;
}
for (auto&& x : ans) {
cout << x << endl;
}
} else
cout << -1 << endl;
}
maine_honzuki