結果

問題 No.241 出席番号(1)
ユーザー nasadigitalnasadigital
提出日時 2015-07-10 22:56:30
言語 C++11
(gcc 11.4.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,317 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 66,788 KB
実行使用メモリ 63,128 KB
最終ジャッジ日時 2023-09-22 10:03:32
合計ジャッジ時間 3,506 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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<n;ctr1++){
        VI t(n,1);
        f.push_back(t);
    }
    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;
}
0