結果

問題 No.177 制作進行の宮森あおいです!
ユーザー chocobochocobo
提出日時 2020-05-07 20:39:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 3,228 bytes
コンパイル時間 1,581 ms
コンパイル使用メモリ 137,188 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-16 08:04:36
合計ジャッジ時間 2,145 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)



















class Dinic {
private:
    struct edge {
        ll to, cap, rev;
    };
    vector<vector<edge>> list;  // グラフの隣接リスト
    vector<ll> level;    // sからの距離
    vector<ll> iter;     // どこまで調べ終わったか
    
public:
    Dinic(ll n) : list(n), level(n), iter(n){}
    
    void add_edge(ll from, ll to, ll cap){
        list[from].push_back({to, cap, (ll)list[to].size()});
        list[to].push_back({from, 0, (ll)list[from].size() - 1});
    }
    
    void bfs(ll s){
        level.assign(level.size(), -1);
        queue<ll> que;
        level[s] = 0;
        que.push(s);
        while(!que.empty()){
            ll v = que.front(); que.pop();
            for(auto &x : list[v]){
                if(x.cap > 0 && level[x.to] < 0){
                    level[x.to] = level[v] + 1;
                    que.push(x.to);
                }
            }
        }
    }
    
    ll dfs(ll v, ll t, ll f){
        if(v == t) return f;
    
        for(ll &i = iter[v]; i < list[v].size(); i++){
            edge &e = list[v][i];
            if(e.cap > 0 && level[v] < level[e.to]){
                ll d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    list[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    
    ll max_flow(ll s, ll t){
        ll flow = 0;
    
        for(;;){
            bfs(s);
            if(level[t] < 0) return flow;
            
            iter.assign(iter.size(), 0);
            
            ll f;
            while((f = dfs(s, t, INF)) > 0){
                flow += f;
            }
        }
    }
};

int main(){
    ll w, n;
    cin >> w >> n;
    vector<ll> J(n);
    REP(i, n){
        cin >> J[i];
    }
    ll m;
    cin >> m;
    vector<ll> c(m);
    REP(i, m){
        cin >> c[i];
    }
    vector<vector<ll>> x(m);
    REP(i, m){
        ll q;
        cin >> q;
        x[i].resize(q);
        REP(j, q){
            cin >> x[i][j];
            x[i][j]--;
        }
    }
    Dinic dic(n + m + 2);
    const ll s = n + m, g = n + m + 1;
    REP(i, n){
        dic.add_edge(s, i, J[i]);
    }
    REP(i, m){
        dic.add_edge(n + i, g, c[i]);
    }
    REP(i, n){
        REP(j, m){
            bool ok = true;
            REP(k, x[j].size()){
                if(x[j][k] == i){
                    ok = false;
                    break;
                }
            }
            if(ok){
                dic.add_edge(i, n + j, J[i]);
            }
        }
    }
    cout << ((dic.max_flow(s, g) >= w)? "SHIROBAKO" : "BANSAKUTSUKITA") << endl;
}
0