結果
問題 | No.241 出席番号(1) |
ユーザー |
![]() |
提出日時 | 2015-09-04 17:55:38 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,881 bytes |
コンパイル時間 | 796 ms |
コンパイル使用メモリ | 91,864 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-30 21:32:00 |
合計ジャッジ時間 | 2,070 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#include <cstdio>#include <cstring>#include <cmath>#include <climits>#include <iostream>#include <iomanip>#include <list>#include <stack>#include <queue>#include <vector>#include <map>#include <set>#include <string>#include <utility>#include <algorithm>#include <numeric>#include <functional>#define FOR(i,a,b) for (int i=(a);i<(b);i++)#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)#define REP(i,n) for (int i=0;i<(n);i++)#define RREP(i,n) for (int i=(n)-1;i>=0;i--)#define ALL(a) (a).begin(),(a).end()using namespace std;typedef long long ll;class BipartiteMatching {int max_v;vector<vector<int>> *G;bool *used;public:int *match;BipartiteMatching(int n) : max_v(n){G = new vector<vector<int>>(max_v);match = new int[max_v];used = new bool[max_v];}~BipartiteMatching(){delete match;delete used;delete G;}void AddEdge(int u, int v) {(*G)[u].push_back(v);(*G)[v].push_back(u);}bool Dfs(int v) {used[v] = true;for (int u : (*G)[v]) {int w = match[u];if (w < 0 || (!used[w] && Dfs(w))) {match[v] = u;match[u] = v;return true;}}return false;}int DoMatching() {int res = 0;memset(match, -1, sizeof(match[0]) * max_v);for (int v = 0; v < max_v; v++) {if (match[v] < 0) {memset(used, false, sizeof(used[0]) * max_v);if (Dfs(v)) res++;}}return res;}};int main(int argc, char *argv[]){cin.tie(0);ios::sync_with_stdio(false);int N;cin >> N;BipartiteMatching bm = BipartiteMatching(N+N);REP(i,N){int x;cin >> x;REP(j,N) if(j!=x) bm.AddEdge(i+N,j);}if (bm.DoMatching() < N) {cout << -1 << endl;return 0;}REP(i,N) cout << bm.match[i+N] << '\n';cout << flush;return 0;}