Submission #23995356


Source Code Expand

Copy
import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import maximum_flow
input = sys.stdin.readline
def main():
n, w = map(int, input().split())
a = list(map(int, input().split()))
S = n
T = n + 1
frm = []
to = []
cap = []
inf = 1 << 30
for i in range(n):
frm.append(S)
to.append(i)
cap.append(w)
frm.append(i)
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import maximum_flow

input = sys.stdin.readline


def main():
    n, w = map(int, input().split())
    a = list(map(int, input().split()))
    S = n
    T = n + 1
    frm = []
    to = []
    cap = []
    inf = 1 << 30
    for i in range(n):
        frm.append(S)
        to.append(i)
        cap.append(w)
        frm.append(i)
        to.append(T)
        cap.append(a[i])

    for i in range(n):
        v = [int(j) - 1 for j in input().split()[1:]]
        for j in v:
            frm.append(i)
            to.append(j)
            cap.append(inf)

    mat = csr_matrix((cap, (frm, to)), (n + 2, n + 2))
    print(sum(a) - maximum_flow(mat, S, T).flow_value)


if __name__ == "__main__":
    main()

Submission Info

Submission Time
Task 040 - Get More Money(★7)
User riantkb
Language Python (3.8.2)
Score 7
Code Size 776 Byte
Status AC
Exec Time 549 ms
Memory 38244 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 7 / 7
Status
AC × 2
AC × 12
Set Name Test Cases
Sample sample01.txt, sample02.txt
All free.txt, killer.txt, max_densest01.txt, max_densest02.txt, max_random00.txt, max_random01.txt, max_random02.txt, random00.txt, random01.txt, random02.txt, sample01.txt, sample02.txt
Case Name Status Exec Time Memory
free.txt AC 549 ms 37488 KB
killer.txt AC 165 ms 37404 KB
max_densest01.txt AC 174 ms 38128 KB
max_densest02.txt AC 170 ms 38244 KB
max_random00.txt AC 170 ms 37580 KB
max_random01.txt AC 173 ms 37860 KB
max_random02.txt AC 169 ms 37576 KB
random00.txt AC 171 ms 37712 KB
random01.txt AC 167 ms 37916 KB
random02.txt AC 169 ms 37652 KB
sample01.txt AC 165 ms 37456 KB
sample02.txt AC 168 ms 37580 KB


2025-04-05 (Sat)
18:36:40 +00:00