結果

問題 No.177 制作進行の宮森あおいです!
ユーザー tkzw_21tkzw_21
提出日時 2015-04-03 08:23:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,155 bytes
コンパイル時間 1,424 ms
コンパイル使用メモリ 159,748 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 03:57:40
合計ジャッジ時間 2,241 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

//Max-Flow,最大流
template<int V>
struct MaxFlow{
	using T = double;
	const T INF = 1<<28;
	
	struct Edge{
		int to,rev;
		T cap;
	};

	vector<Edge> g[V];
	int level[V];
	int iter[V];

	 void add(int from, int to, T cap) {
        g[from].push_back(Edge{to, (int)g[to].size(), cap});
        g[to].push_back(Edge{from, (int)g[from].size()-1, 0});
    }
    void add_multi(int from, int to, T cap) {
        g[from].push_back(Edge{to, (int)g[to].size(), cap});
        g[to].push_back(Edge{from, (int)g[from].size()-1, cap});
    }

    void bfs(int s){
    	fill_n(level,V,-1);
    	queue<int> que;
    	level[s] = 0;
    	que.push(s);
    	while(!que.empty()){
    		int v = que.front();que.pop();
    		for(Edge e: g[v]){
    			if(e.cap <= 0)continue;
    			if(level[e.to] < 0){
    				level[e.to] = level[v] + 1;
    				que.push(e.to);
    			}
    		}
    	}
    }

    T dfs(int v,int t,T f){
    	if(v == t)return f;
    	for(int &i = iter[v];i < g[v].size();i++){
    		Edge &e = g[v][i];
    		if(e.cap <= 0)continue;
    		if(level[v] < level[e.to]){
    			T d = dfs(e.to,t,min(f,e.cap));
    			if(d <= 0)continue;
    			e.cap -= d;
    			g[e.to][e.rev].cap += d;
    			return d;
    		}
    	}
    	return 0;
    }
    T exec(int s,int t){
    	T flow = 0;
    	while(true){
    		bfs(s);
    		if(level[t] < 0)return flow;
    		fill_n(iter,V,0);
    		T f;
    		while((f = dfs(s,t,INF)) > 0){
    			flow += f;
    		}
    	}
    }
};

int main(void) {
	int w,n;
	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<bool>> link(n,vector<bool>(m,true));
	for(int i=0;i<m;i++){
		int q;cin >> q;
		for(int j=0;j<q;j++){
			int x;cin >> x;x--;
			link[x][i] = false;
		}
	}

	MaxFlow<120> mf;
	for(int i=0;i<n;i++)mf.add(n+m,i,j[i]);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(link[i][j])mf.add(i,j+n,1<<28);
		}
	}
	for(int i=0;i<m;i++)mf.add(i+n,n+m+1,c[i]);

	cout << (mf.exec(m+n,m+n+1)>=w ? "SHIROBAKO" : "BANSAKUTSUKITA") << endl;

	return 0;
}
0