結果

問題 No.177 制作進行の宮森あおいです!
ユーザー Manuel1024Manuel1024
提出日時 2021-04-05 03:05:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 2,144 bytes
コンパイル時間 859 ms
コンパイル使用メモリ 82,996 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 14:22:07
合計ジャッジ時間 1,901 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 13 ms
4,376 KB
testcase_10 AC 20 ms
4,376 KB
testcase_11 AC 18 ms
4,376 KB
testcase_12 AC 10 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

template<class T>
class MaxFlowGraph{
private:
    struct Edge{
        int to;
        T cap;
        int rev;
    };
    using graph = vector<vector<Edge>>;
    graph G;
    vector<bool> used;

public:
    MaxFlowGraph(int n){
        G = graph(n);
        used = vector<bool>(n, false);
    }

    void add_edge(int from, int to, T cap){
        G[from].push_back({to, cap, (int)G[to].size()});
        G[to].push_back({from, 0, (int)G[from].size()-1});
    }

    T dfs(int v, int t, T f){
        if(v == t) return f;
        used[v] = true;
        for(int i = 0; i < G[v].size(); i++){
            auto &e = G[v][i];
            if(used[e.to] || e.cap == 0) continue;
            T d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
        return 0;
    }

    T flow(int s, int t){
        T maxflow = 0;
        while(true){
            fill(used.begin(), used.end(), false);
            T INF = 1001001001;
            T f = dfs(s, t, INF);
            if(f == 0) return maxflow;
            else maxflow += f;
        }
    }
};

int main(){
    int w;
    cin >> w;
    int n;
    cin >> n;
    vector<int> j(n);
    for(auto &p: j) cin >> p;
    int m;
    cin >> m;
    vector<int> c(m);
    for(auto &p: c) cin >> p;

    vector<vector<int>> x(m, vector<int>(n, 1));
    for(int i = 0; i < m; i++){
        int q;
        cin >> q;
        while(q--){
            int xi;
            cin >> xi;
            x[i][xi-1] = 0;
        }
    }

    MaxFlowGraph<int> G(n+m+2);
    const int s = n+m;
    const int t = n+m+1;
    for(int i = 0; i < n; i++) G.add_edge(s, i, j[i]);
    for(int i = 0; i < m; i++) G.add_edge(n+i, t, c[i]);
    for(int i = 0; i < m; i++){
        for(int ii = 0; ii < n; ii++){
            if(x[i][ii] == 1) G.add_edge(ii, n+i, 1001001001);
        }
    }

    int maxflow = G.flow(s, t);
    if(maxflow >= w) cout << "SHIROBAKO" << endl;
    else cout << "BANSAKUTSUKITA" << endl;
    return 0;
}
0