結果
問題 | No.241 出席番号(1) |
ユーザー |
![]() |
提出日時 | 2016-05-05 22:46:18 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,492 bytes |
コンパイル時間 | 775 ms |
コンパイル使用メモリ | 66,032 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-30 21:35:53 |
合計ジャッジ時間 | 1,930 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>using namespace std;#define RREP(i,s,e) for (i = s; i >= e; i--)#define rrep(i,n) RREP(i,(int)(n)-1,0)#define REP(i,s,e) for (i = s; i <= e; i++)#define rep(i,n) REP(i,0,(int)(n)-1)#define INF 100000000typedef long long ll;int n;vector<pair<pair<int,int>,int>> e[102];bool used[102];int dfs(int v) {if (used[v])return 0;used[v] = true;if (v == 2*n+1)return 1;for (auto& p : e[v]) {int to = p.first.first;int& cap = p.first.second;int rev = p.second;if (cap > 0) {if (dfs(to)) {cap--;e[to][rev].first.second++;return 1;}}}return 0;}void add_edge(int from, int to) {e[from].push_back(make_pair(make_pair(to,1),e[to].size()));e[to].push_back(make_pair(make_pair(from,0),e[from].size()-1));}int main() {int i, j, flows = 0;cin >> n;rep (i,n) {int a;cin >> a;rep (j,n) if (j != a) add_edge(i,j+n);add_edge(2*n,i);add_edge(i+n,2*n+1);}while (dfs(2*n)) {fill(used,used+2*n+2,false);flows++;}if (flows == n) {rep (i,n) {for (auto p : e[i]) {if (p.first.second == 0)cout << p.first.first - n << endl;}}}elsecout << -1 << endl;return 0;}