結果

問題 No.177 制作進行の宮森あおいです!
ユーザー milanis48663220milanis48663220
提出日時 2020-06-21 01:57:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 2,564 bytes
コンパイル時間 1,181 ms
コンパイル使用メモリ 97,888 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 17:59:25
合計ジャッジ時間 2,210 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 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,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 11 ms
4,376 KB
testcase_10 AC 18 ms
4,376 KB
testcase_11 AC 15 ms
4,376 KB
testcase_12 AC 9 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

const int INF =  100000000;

struct edge {int to, cap, rev;};

class FordFolkerson{
    public:
        FordFolkerson(int n){
            N = n;
            G = vector<vector<edge>>(n, vector<edge>());
            used = vector<bool>(n, false);
        }

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

        int max_flow(int s, int t){
            int flow = 0;
            while(true){
                clear_used();
                int f = dfs(s, t, INF);
                if(f == 0){
                    break;
                }
                flow += f;
            }
            return flow;
        }

    private:
        vector<vector<edge>> G;
        vector<bool> used;
        int N;
        void clear_used(){
            for(int i = 0; i < N; i++) used[i] = false;
        }

        int dfs(int v, int t, int f){
            if(v == t) return f;
            used[v] = true;
            for(int i = 0; i < G[v].size(); i++){
                edge &e = G[v][i];
                if(!used[e.to] && e.cap > 0){
                    int 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;
        }
};

int W;
int N, M;
int J[50], C[50];
int th = 100000;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> W >> N;
    for(int i = 0; i < N; i++){
        cin >> J[i];
    }
    cin >> M;
    for(int i = 0; i < M; i++){
        cin >> C[i];
    }
    FordFolkerson ff(N+M+2);
    for(int i = 0; i < N; i++){
        ff.add_edge(0, i+1, J[i]);
    }
    for(int i = 0; i < M; i++){
        ff.add_edge(N+i+1, N+M+1, C[i]);
    }
    for(int i = 0; i < M; i++){
        set<int> st;
        int q; cin >> q;
        for(int j = 0; j < q; j++){
            int x; cin >> x; x--;
            st.insert(x);
        }
        for(int j = 0; j < N; j++){
            if(st.count(j) == 0){
                ff.add_edge(j+1, N+i+1, 100000);
            }
        }
    }
    if(ff.max_flow(0, N+M+1) >= W) cout << "SHIROBAKO" << endl;
    else cout << "BANSAKUTSUKITA" << endl;
}
0