結果

問題 No.177 制作進行の宮森あおいです!
ユーザー @abcde@abcde
提出日時 2019-06-28 04:59:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 2,432 bytes
コンパイル時間 1,680 ms
コンパイル使用メモリ 176,340 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 21:10:24
合計ジャッジ時間 2,878 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 17 ms
4,376 KB
testcase_11 AC 16 ms
4,376 KB
testcase_12 AC 10 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: メンバ関数 ‘void Flow::add_edge(int, int, int)’ 内:
main.cpp:23:53: 警告: narrowing conversion of ‘((Flow*)this)->Flow::G[to].std::vector<Flow::edge>::size()’ from ‘std::vector<Flow::edge>::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing]
   23 |         G[from].push_back((edge){to, cap, G[to].size()});
      |                                           ~~~~~~~~~~^~
main.cpp:24:56: 警告: narrowing conversion of ‘(((Flow*)this)->Flow::G[from].std::vector<Flow::edge>::size() - 1)’ from ‘std::vector<Flow::edge>::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing]
   24 |         G[to].push_back((edge){from, 0, G[from].size() - 1});
      |                                         ~~~~~~~~~~~~~~~^~~

ソースコード

diff #

// 下記, 解説サイトを参照して解答.
// http://mmxsrup.hatenablog.com/entry/2016/09/07/140617
// -> 最大流(Ford-Fulkerson) の ライブラリ と 見做す.
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;
const int MAX_V = 20000;

struct Flow{
    // 辺.
    struct edge{
        int to;
        int cap;
        int rev;
    };
    // 隣接リスト.
    vector<edge> G[MAX_V];
    // 訪問フラグ.
    bool used[MAX_V];
    void add_edge(int from, int to, int cap){
        G[from].push_back((edge){to, cap, G[to].size()});
        G[to].push_back((edge){from, 0, G[from].size() - 1});
    }

    // 増加パスを探す
    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;
    }
    
    //s -> t への最大流.
    int max_flow(int s, int t){
        int flow = 0;
        while(1){
            memset(used, 0, sizeof(used));
            int f = dfs(s, t, INF);
            if(f == 0) return flow;
            flow += f;
        }
    }
};

int j[10010], c[10010];
set<int> x[55];

int main(void){

    // 1. 入力情報.
    int w, n;
    scanf("%d %d", &w, &n);
    for(int i = 0; i < n; i++) scanf("%d", j + i);
    
    int m;
    scanf("%d", &m);
    for(int i = 0; i < m; i++) scanf("%d", c + i);
    
    for(int i = 0; i < m; i++){
        int q;
        scanf("%d", &q);
        for(int j = 0; j < q; j++){
            int tmp;
            scanf("%d", &tmp);
            tmp--;
            x[i].insert(tmp);
        }
    }
    
    // 2. 最大流(Ford-Fulkerson).
    Flow mf;
    for(int i = 0; i < n; i++) mf.add_edge(0, i + 1, j[i]);
    for(int i = 0; i < m; i++) mf.add_edge(100 + i, 200, c[i]);
    for(int v = 0; v < m; v++){
        for(int u = 0; u < n; u++){
           if(x[v].count(u) == 0) mf.add_edge(u + 1, v + 100, INF);
        }
    }
    
    // 3. 出力.
    LL ans = mf.max_flow(0, 200);
    if(ans >= w) printf("SHIROBAKO\n");
    else         printf("BANSAKUTSUKITA\n");
    return 0;

}
0