結果
問題 |
No.241 出席番号(1)
|
ユーザー |
![]() |
提出日時 | 2015-07-12 00:57:29 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,419 bytes |
コンパイル時間 | 607 ms |
コンパイル使用メモリ | 67,848 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-30 21:29:08 |
合計ジャッジ時間 | 1,994 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#include <iostream> #include <cstring> #include <queue> #include <vector> #include <utility> using namespace std; typedef pair<int,int> ii; typedef vector<int> VI; typedef vector<VI> VVI; bool FindMatch(int i, const VVI &w, VI &mr, VI &mc, VI &seen) { for (int j = 0; j < w[i].size(); j++) { if (w[i][j] && !seen[j]) { seen[j] = true; if (mc[j] < 0 || FindMatch(mc[j], w, mr, mc, seen)) { mr[i] = j; mc[j] = i; return true; } } } return false; } int BipartiteMatching(const VVI &w, VI &mr, VI &mc) { mr = VI(w.size(), -1); mc = VI(w[0].size(), -1); int ct = 0; for (int i = 0; i < w.size(); i++) { VI seen(w[0].size()); if (FindMatch(i, w, mr, mc, seen)) ct++; } return ct; } int main(int argc, const char * argv[]) { int n; cin>>n; VVI f; for(int ctr1=0;ctr1<50;ctr1++){ VI t(50,0); f.push_back(t); } for(int ctr1=0;ctr1<n;ctr1++) for(int ctr2=0;ctr2<n;ctr2++) f[ctr1][ctr2]=1; for(int ctr1=0;ctr1<n;ctr1++){ int a; cin>>a; f[ctr1][a]=0; } VI rez,rez2; int r=BipartiteMatching(f, rez, rez2); if(r!=n){ cout<<-1; } else{ for(int ctr1=0;ctr1<n;ctr1++){ cout<<rez[ctr1]<<endl; } } return 0; }