結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
54,528 KB
testcase_01 AC 48 ms
54,272 KB
testcase_02 AC 49 ms
54,656 KB
testcase_03 AC 48 ms
54,656 KB
testcase_04 AC 49 ms
54,656 KB
testcase_05 AC 49 ms
55,296 KB
testcase_06 AC 50 ms
54,784 KB
testcase_07 AC 50 ms
54,528 KB
testcase_08 AC 50 ms
54,784 KB
testcase_09 AC 49 ms
54,400 KB
testcase_10 AC 49 ms
54,528 KB
testcase_11 AC 49 ms
54,400 KB
testcase_12 AC 50 ms
55,040 KB
testcase_13 AC 58 ms
61,440 KB
testcase_14 AC 104 ms
77,440 KB
testcase_15 WA -
testcase_16 AC 85 ms
72,960 KB
testcase_17 AC 90 ms
74,880 KB
testcase_18 AC 78 ms
69,248 KB
testcase_19 AC 78 ms
69,120 KB
testcase_20 AC 49 ms
54,656 KB
testcase_21 AC 73 ms
67,200 KB
testcase_22 AC 103 ms
77,952 KB
testcase_23 AC 105 ms
77,696 KB
testcase_24 AC 108 ms
77,824 KB
testcase_25 AC 106 ms
77,824 KB
testcase_26 AC 102 ms
77,696 KB
testcase_27 AC 112 ms
77,824 KB
testcase_28 AC 106 ms
78,208 KB
testcase_29 AC 92 ms
74,496 KB
testcase_30 AC 107 ms
78,080 KB
testcase_31 AC 89 ms
74,496 KB
testcase_32 AC 106 ms
77,568 KB
testcase_33 AC 60 ms
61,952 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 60 ms
62,208 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 77 ms
68,352 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 63 ms
63,232 KB
testcase_59 AC 90 ms
72,448 KB
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 AC 106 ms
77,952 KB
testcase_64 AC 85 ms
71,424 KB
testcase_65 AC 100 ms
77,440 KB
testcase_66 AC 52 ms
55,168 KB
testcase_67 AC 57 ms
61,440 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