結果

問題 No.241 出席番号(1)
ユーザー tnoda_tnoda_
提出日時 2015-09-04 17:55:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,881 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 90,400 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 17:50:58
合計ジャッジ時間 2,510 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0