結果

問題 No.177 制作進行の宮森あおいです!
ユーザー ytftytft
提出日時 2021-03-18 14:46:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,284 bytes
コンパイル時間 2,143 ms
コンパイル使用メモリ 178,420 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-10 11:41:34
合計ジャッジ時間 3,355 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;


int typical_maxflow(vector<vector<int>> graph,int start,int goal){//graphは隣接行列
    int N=graph.size();
    int ans=0;
    int pointer=0;
    int m;
    vector<int> reach;
    queue<int> q;
    vector<int> temp;
    int counter=0;
    while(true){
        reach.resize(0);
        reach.resize(N,-1);
        queue<int> ().swap(q);
        reach[start]=0;
        q.push(start);
        while(!q.empty() && q.front()!=goal){
            for(int i=0;i<N;i++){
                if(graph[q.front()][i]>0 && reach[i]==-1){
                    reach[i]=q.front();
                    q.push(i);
                }
            }
            q.pop();
        }
        if(q.empty()){
            return ans;
        }
        temp={};
        pointer=goal;
        while(pointer!=start){
            temp.push_back(pointer);
            pointer=reach[pointer];
        }
        temp.push_back(start);
        m=graph[temp[1]][temp[0]];
        for(int i=1;i<temp.size()-1;i++){
            m=min(m,graph[temp[i+1]][temp[i]]);
        }
        ans+=m;
        for(int i=0;i<temp.size()-1;i++){
            graph[temp[i+1]][temp[i]]-=m;
            graph[temp[i]][temp[i+1]]+=m;
        }
    }
}

int main(){
    int W,N;
    int inf=INT_MAX/2;
    cin>>W>>N;
    vector<int> J(N);
    for(int i=0;i<N;i++){
        cin>>J[i];
    }
    int M;
    cin>>M;
    vector<int> C(M);
    for(int i=0;i<M;i++){
        cin>>C[i];
    }
    vector<vector<int>> graph(N+M+2,vector<int>(N+M+2,inf));
    for(int i=0;i<N+M+2;i++){
        graph[i][i]=0;
    }
    graph[0][1]=0;
    graph[1][0]=0;
    for(int i=2;i<2+N;i++){
        graph[0][i]=J[i-2];
        graph[i][0]=0;
        graph[i][1]=0;
        graph[1][i]=0;
        for(int j=2;j<2+N;j++){
            graph[i][j]=0;
        }
    }
    for(int i=2+N;i<2+M+N;i++){
        graph[i][1]=C[i-2-N];
        graph[i][0]=0;
        graph[0][i]=0;
        graph[1][i]=0;
        for(int j=2;j<2+M+N;j++){
            graph[i][j]=0;
        }
    }
    int Q,X;
    for(int i=0;i<M;i++){
        cin>>Q;
        for(int j=0;j<Q;j++){
            cin>>X;
            graph[X+1][i+N+2]=0;
        }
    }
    
    cout<<((W<=typical_maxflow(graph,0,1))?"SHIROBAKO":"BANSAKUTSUKITA")<<endl;
}
0