結果

問題 No.1984 [Cherry 4th Tune *] Dilemma
ユーザー sotanishysotanishy
提出日時 2022-06-17 23:20:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,327 bytes
コンパイル時間 518 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 78,464 KB
最終ジャッジ日時 2024-04-26 01:48:16
合計ジャッジ時間 9,165 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,576 KB
testcase_01 AC 41 ms
54,528 KB
testcase_02 AC 39 ms
54,912 KB
testcase_03 AC 39 ms
54,400 KB
testcase_04 AC 40 ms
54,784 KB
testcase_05 AC 41 ms
54,784 KB
testcase_06 AC 39 ms
54,784 KB
testcase_07 AC 42 ms
54,656 KB
testcase_08 AC 39 ms
54,528 KB
testcase_09 AC 40 ms
54,784 KB
testcase_10 AC 39 ms
54,656 KB
testcase_11 AC 38 ms
55,296 KB
testcase_12 AC 39 ms
54,912 KB
testcase_13 AC 44 ms
62,208 KB
testcase_14 AC 77 ms
77,440 KB
testcase_15 WA -
testcase_16 AC 70 ms
73,216 KB
testcase_17 AC 72 ms
74,612 KB
testcase_18 AC 62 ms
69,760 KB
testcase_19 AC 63 ms
68,864 KB
testcase_20 AC 43 ms
55,168 KB
testcase_21 AC 58 ms
67,456 KB
testcase_22 AC 85 ms
77,568 KB
testcase_23 AC 84 ms
77,824 KB
testcase_24 AC 91 ms
78,336 KB
testcase_25 AC 88 ms
78,464 KB
testcase_26 AC 84 ms
77,964 KB
testcase_27 AC 91 ms
78,012 KB
testcase_28 AC 85 ms
78,080 KB
testcase_29 AC 74 ms
74,568 KB
testcase_30 AC 85 ms
78,208 KB
testcase_31 AC 73 ms
75,136 KB
testcase_32 AC 90 ms
77,836 KB
testcase_33 AC 56 ms
62,592 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 46 ms
62,336 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 61 ms
68,864 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 AC 52 ms
63,616 KB
testcase_59 AC 72 ms
73,216 KB
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 AC 83 ms
78,212 KB
testcase_64 AC 67 ms
72,192 KB
testcase_65 AC 77 ms
77,788 KB
testcase_66 AC 43 ms
55,680 KB
testcase_67 AC 48 ms
62,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class Dinic:
    class Edge:
        def __init__(self, v, cap, rev):
            self.v = v
            self.cap = cap
            self.rev = rev

    def __init__(self, V):
        self.V = V
        self.G = [[] for _ in range(V)]

    def add_edge(self, u, v, cap):
        self.G[u].append(self.Edge(v, cap, len(self.G[v])))
        self.G[v].append(self.Edge(u, 0, len(self.G[u])-1))

    # calculate the shortest distance from s
    def bfs(self, s):
        from collections import deque

        self.level = [-1] * self.V
        self.level[s] = 0
        queue = deque()
        queue.append(s)
        while queue:
            u = queue.popleft()
            for e in self.G[u]:
                if e.cap > 0 and self.level[e.v] == -1:
                    self.level[e.v] = self.level[u] + 1
                    queue.append(e.v)

    # find a path
    def dfs(self, u, t, f):
        if u == t:
            return f
        i = self.iter[u]
        while i < len(self.G[u]):
            e = self.G[u][i]
            if e.cap > 0 and self.level[u] < self.level[e.v]:
                d = self.dfs(e.v, t, min(f, e.cap))
                if d > 0:
                    e.cap -= d
                    self.G[e.v][e.rev].cap += d
                    return d
            i += 1
            self.iter[u] += 1
        return 0

    # find the max flow from s to v
    def max_flow(self, s, t):
        flow = 0
        INF = 10**18
        while True:
            self.bfs(s)
            if self.level[t] == -1:
                return flow
            self.iter = [0] * self.V
            while True:
                f = self.dfs(s, t, INF)
                if f == 0:
                    break
                flow += f

    def min_cut(self, s):
        visited = [False] * self.V
        st = [s]
        visited[s] = True
        while st:
            u = st.pop()
            for e in self.G[u]:
                if e.cap > 0 and not visited[e.v]:
                    visited[e.v] = True
                    st.append(e.v)
        return visited



N, M, K, P = map(int, input().split())
E = list(map(int, input().split()))
F = list(map(int, input().split()))
V = list(map(int, input().split()))
flow = Dinic(N+M+K+2)
s = N+M+K
t = s+1
ans = 0
for i in range(N):
    flow.add_edge(s, i, E[i])
    flow.add_edge(i, t, 0)
    ans += E[i]
for i in range(M):
    flow.add_edge(s, N+i, 0)
    flow.add_edge(N+i, t, F[i])
    ans += F[i]
for i in range(K):
    flow.add_edge(s, N+M+i, 0)
    flow.add_edge(N+M+i, t, V[i])
for i in range(N):
    _, *A = list(map(int, input().split()))
    for a in A:
        a -= 1
        flow.add_edge(i, N+M+a, 10**18)
for i in range(P):
    I, J = map(int, input().split())
    I -= 1
    J -= 1
    flow.add_edge(I, N+J, 10**18)
    flow.add_edge(N+J, I, 10**18)
ans -= flow.max_flow(s, t)
use = flow.min_cut(s)
goals = []
actions = []
preps = []
for i in range(N+M+K):
    if i < N:
        if use[i]:
            goals.append(i+1)
    elif i < N+M:
        if not use[i]:
            actions.append(i-N+1)
    else:
        if use[i]:
            preps.append(i-N-M+1)
print(ans)
print(len(goals) + len(actions) + len(preps))
for i in preps:
    print("Preparation", i)
for i in goals:
    print("Goal", i)
for i in actions:
    print("Action", i)
0