結果
問題 | No.241 出席番号(1) |
ユーザー |
![]() |
提出日時 | 2018-11-15 20:12:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,560 bytes |
コンパイル時間 | 1,923 ms |
コンパイル使用メモリ | 205,200 KB |
最終ジャッジ日時 | 2025-01-06 16:43:32 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} struct BiMatch{ int L,R; vector<vector<int> > G; vector<int> match,level; BiMatch(){} BiMatch(int L,int R):L(L),R(R),G(L+R),match(L+R,-1),level(L){} void add_edge(int u,int v){ G[u].push_back(v+L); G[v+L].push_back(u); } bool bfs(){ queue<int> q; for(int i=0;i<L;i++){ level[i]=-1; if(match[i]<0){ level[i]=0; q.emplace(i); } } while(!q.empty()){ int v=q.front();q.pop(); for(int u:G[v]){ int w=match[u]; if(w<0) return true; if(level[w]<0){ level[w]=level[v]+1; q.emplace(w); } } } return false; } bool dfs(int v){ for(int u:G[v]){ int w=match[u]; if(w<0||(level[w]>level[v]&&dfs(w))){ match[v]=u; match[u]=v; return true; } } return false; } int build(){ int res=0; while(bfs()) for(int i=0;i<L;i++) if(match[i]<0&&dfs(i)) res++; return res; } }; //INSERT ABOVE HERE signed main(){ int n; cin>>n; BiMatch bm(n,n); for(int i=0;i<n;i++){ int a; cin>>a; for(int j=0;j<n;j++) if(j!=a) bm.add_edge(i,j); } int k=bm.build(); if(k!=n){ cout<<-1<<endl; return 0; } for(int i=0;i<n;i++) cout<<bm.match[i]-n<<endl; return 0; }