結果

問題 No.177 制作進行の宮森あおいです!
ユーザー kou6839kou6839
提出日時 2015-06-21 00:31:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 262 ms / 2,000 ms
コード長 2,215 bytes
コンパイル時間 4,432 ms
コンパイル使用メモリ 75,584 KB
実行使用メモリ 59,192 KB
最終ジャッジ日時 2023-09-21 22:15:05
合計ジャッジ時間 8,242 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
55,380 KB
testcase_01 AC 145 ms
55,608 KB
testcase_02 AC 135 ms
55,756 KB
testcase_03 AC 157 ms
55,652 KB
testcase_04 AC 158 ms
56,060 KB
testcase_05 AC 198 ms
56,304 KB
testcase_06 AC 227 ms
56,724 KB
testcase_07 AC 175 ms
57,704 KB
testcase_08 AC 190 ms
56,144 KB
testcase_09 AC 241 ms
56,640 KB
testcase_10 AC 262 ms
58,640 KB
testcase_11 AC 248 ms
59,192 KB
testcase_12 AC 242 ms
58,752 KB
testcase_13 AC 127 ms
55,748 KB
testcase_14 AC 129 ms
55,660 KB
testcase_15 AC 129 ms
55,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class MaximumFlow {
	private ArrayList<Edge>[] G;
	private boolean[] used;
	
	public class Edge{
		int to;
		int cap;
		int rev;
		
		public Edge(int to,int cap, int rev){
			this.to = to;
			this.cap = cap;
			this.rev = rev;
		}
	}
	
	public MaximumFlow(int v){
		used = new boolean[v];
		G = new ArrayList[v];
		for(int i=0;i<v;i++){
			G[i]=new ArrayList<>();
		}
	}	
	
	public void addEdge(int from,int to, int cap){
		G[from].add(new Edge(to, cap, G[to].size()));
		G[to].add(new Edge(from, 0, G[from].size()-1));
	}
	
	private 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 edge = G[v].get(i);
			
			if(!used[edge.to] && edge.cap>0){
				int d = dfs(edge.to,t,Math.min(f,edge.cap));
				
				if(d>0){
					edge.cap-=d;
					G[edge.to].get(edge.rev).cap += d;
					return d;
				}
			}
		}
		
		return 0;
	}
	
	public int maxFlow(int s,int t){
		int flow = 0;
		for(;;){
			Arrays.fill(used, false);
			int f = dfs(s, t, Integer.MAX_VALUE);
			
			if(f==0) return flow;
			flow+=f;
		}
	}
}
public class Main {
    public static void main(String[] args){
        // TODO 自動生成されたメソッド・スタブ
    	Scanner sc = new Scanner(System.in);
    	
    	int W = sc.nextInt();
    	
    	int N = sc.nextInt();
    	int[] J = new int[N];
    	for(int i=0;i<N;i++){
    		J[i]=sc.nextInt();
    	}
    	int M = sc.nextInt();
    	int[] C = new int[M];
    	for(int i=0;i<M;i++){
    		C[i]=sc.nextInt();
    	}
    	
    	MaximumFlow MF = new MaximumFlow(N+M+2);
    	 for (int i = 0; i < N; i++) {
              MF.addEdge(N + M, i, J[i]);
          }
          for (int j = 0; j < M; j++) {
              MF.addEdge(N + j, N + M + 1, C[j]);
          }
    	for(int i=0;i<M;i++){
    		int q = sc.nextInt();
    		boolean[] hate = new boolean[N];
    		for(int j=0;j<q;j++){
    			hate[sc.nextInt()-1]=true;
    		}
    		for(int j=0;j<N;j++){
    			if(!hate[j]){
    				MF.addEdge(j, N+i, J[j]);
    			}
    		}
    	}
    	
    	int v = MF.maxFlow(N+M, N+M+1);
    	if(v>=W){
    		System.out.println("SHIROBAKO");
    	}else{
    		System.out.println("BANSAKUTSUKITA");
    	}
    }
}
0