結果

問題 No.177 制作進行の宮森あおいです!
ユーザー tcltktcltk
提出日時 2021-06-27 15:25:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 2,520 bytes
コンパイル時間 545 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 84,524 KB
最終ジャッジ日時 2023-09-07 17:29:06
合計ジャッジ時間 5,204 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 210 ms
80,972 KB
testcase_01 AC 213 ms
81,088 KB
testcase_02 AC 212 ms
81,032 KB
testcase_03 AC 210 ms
80,948 KB
testcase_04 AC 210 ms
80,724 KB
testcase_05 AC 221 ms
83,232 KB
testcase_06 AC 229 ms
84,196 KB
testcase_07 AC 215 ms
81,052 KB
testcase_08 AC 220 ms
83,792 KB
testcase_09 AC 237 ms
84,448 KB
testcase_10 AC 238 ms
84,508 KB
testcase_11 AC 237 ms
84,524 KB
testcase_12 AC 234 ms
84,372 KB
testcase_13 AC 214 ms
81,032 KB
testcase_14 AC 211 ms
81,012 KB
testcase_15 AC 210 ms
80,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


sys.setrecursionlimit(1000000)

# _INPUT = """1
# 1
# 10
# 1
# 100
# 1 1
# """
# sys.stdin = io.StringIO(_INPUT)

class Dinic:
    def __init__(self, n):
        self.n = n
        self.links = [[] for _ in range(n)]
        self.depth = None
        self.progress = None
 
    def add_link(self, _from, to, cap):
        self.links[_from].append([cap, to, len(self.links[to])])
        self.links[to].append([0, _from, len(self.links[_from]) - 1])
 
    def bfs(self, s):
        depth = [-1] * self.n
        depth[s] = 0
        q = collections.deque([s])
        while q:
            v = q.popleft()
            for cap, to, rev in self.links[v]:
                if cap > 0 and depth[to] < 0:
                    depth[to] = depth[v] + 1
                    q.append(to)
        self.depth = depth
 
    def dfs(self, v, t, flow):
        if v == t:
            return flow
        links_v = self.links[v]
        for i in range(self.progress[v], len(links_v)):
            self.progress[v] = i
            cap, to, rev = link = links_v[i]
            if cap == 0 or self.depth[v] >= self.depth[to]:
                continue
            d = self.dfs(to, t, min(flow, cap))
            if d == 0:
                continue
            link[0] -= d
            self.links[to][rev][0] += d
            return d
        return 0
 
    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.depth[t] < 0:
                return flow
            self.progress = [0] * self.n
            current_flow = self.dfs(s, t, INF)
            while current_flow > 0:
                flow += current_flow
                current_flow = self.dfs(s, t, INF)

INF = 10**10

W = int(input())
N = int(input())
J = list(map(int, input().split()))
M = int(input())
C = list(map(int, input().split()))

dinic = Dinic(N+M+2)
hate = [None for _ in range(M)]
for j in range(M):
    data = list(map(int, input().split()))
    hate[j] = set(map(lambda x: x-1, data[1:]))

for i in range(N):
    dinic.add_link(0, i+1, J[i])
    for j in range(M):
        if i not in hate[j]:
            dinic.add_link(i+1, j+N+1, INF)
for j in range(M):
    dinic.add_link(j+N+1, N+M+1, C[j])

flow = dinic.max_flow(0, N+M+1)
if flow >= W:
    print('SHIROBAKO')
else:
    print('BANSAKUTSUKITA')
0