Submission #7580976


Source Code Expand

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from collections import deque
    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 = 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, float('inf'))
                while current_flow > 0:
                    flow += current_flow
                    current_flow = self.dfs(s, t, float('inf'))
    # input
    n,g,e=map(int,input().split())
    flow=Dinic(n+1)
    for p in map(int,input().split()):
        flow.add_link(p,n,1)
        flow.add_link(n,p,1)
    for _ in range(e):
        a,b=map(int,input().split())
        flow.add_link(a,b,1)
        flow.add_link(b,a,1)
    print(flow.max_flow(0,n))
resolve()

Submission Info

Submission Time
Task D - 浮気予防
User moni0627
Language PyPy3 (2.4.0)
Score 100
Code Size 2328 Byte
Status AC
Exec Time 222 ms
Memory 43628 KB

Judge Result

Set Name part All
Score / Max Score 99 / 99 1 / 1
Status
AC × 27
AC × 61
Set Name Test Cases
part test_01_AB.txt, test_02_AB.txt, test_03_AB.txt, test_04_AB.txt, test_05_AB.txt, test_06_AB.txt, test_07_AB.txt, test_08_AB.txt, test_09_AB.txt, test_10_AB.txt, test_11_AB.txt, test_12_AB.txt, test_13_AB.txt, test_14_AB.txt, test_15_AB.txt, test_16_AB.txt, test_17_AB.txt, test_18_AB.txt, test_19_AB.txt, test_20_AB.txt, test_21_AB.txt, test_22_AB.txt, test_23_AB.txt, test_24_AB.txt, test_25_AB.txt, test_41_AB.txt, test_47_AB.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt, test_01_AB.txt, test_02_AB.txt, test_03_AB.txt, test_04_AB.txt, test_05_AB.txt, test_06_AB.txt, test_07_AB.txt, test_08_AB.txt, test_09_AB.txt, test_10_AB.txt, test_11_AB.txt, test_12_AB.txt, test_13_AB.txt, test_14_AB.txt, test_15_AB.txt, test_16_AB.txt, test_17_AB.txt, test_18_AB.txt, test_19_AB.txt, test_20_AB.txt, test_21_AB.txt, test_22_AB.txt, test_23_AB.txt, test_24_AB.txt, test_25_AB.txt, test_26_A.txt, test_27_A.txt, test_28_A.txt, test_29_A.txt, test_30_A.txt, test_31_A.txt, test_32_A.txt, test_33_A.txt, test_34_A.txt, test_35_A.txt, test_36_A.txt, test_37_A.txt, test_38_A.txt, test_39_A.txt, test_40_A.txt, test_41_AB.txt, test_42_A.txt, test_43_A.txt, test_44_A.txt, test_45_A.txt, test_46_A.txt, test_47_AB.txt, test_48_A.txt, test_49_A.txt, test_50_A.txt, test_51_A.txt
Case Name Status Exec Time Memory
sample_01.txt AC 162 ms 38256 KB
sample_02.txt AC 163 ms 38256 KB
sample_03.txt AC 163 ms 38256 KB
sample_04.txt AC 163 ms 38256 KB
sample_05.txt AC 162 ms 38256 KB
test_01_AB.txt AC 166 ms 38256 KB
test_02_AB.txt AC 165 ms 38256 KB
test_03_AB.txt AC 172 ms 38256 KB
test_04_AB.txt AC 166 ms 38256 KB
test_05_AB.txt AC 173 ms 38256 KB
test_06_AB.txt AC 168 ms 38256 KB
test_07_AB.txt AC 163 ms 38256 KB
test_08_AB.txt AC 162 ms 38256 KB
test_09_AB.txt AC 163 ms 38256 KB
test_10_AB.txt AC 162 ms 38256 KB
test_11_AB.txt AC 164 ms 38256 KB
test_12_AB.txt AC 164 ms 38256 KB
test_13_AB.txt AC 162 ms 38256 KB
test_14_AB.txt AC 163 ms 38256 KB
test_15_AB.txt AC 164 ms 38256 KB
test_16_AB.txt AC 166 ms 38256 KB
test_17_AB.txt AC 167 ms 38384 KB
test_18_AB.txt AC 164 ms 38256 KB
test_19_AB.txt AC 166 ms 38256 KB
test_20_AB.txt AC 165 ms 38256 KB
test_21_AB.txt AC 162 ms 38256 KB
test_22_AB.txt AC 162 ms 38256 KB
test_23_AB.txt AC 163 ms 38256 KB
test_24_AB.txt AC 162 ms 38256 KB
test_25_AB.txt AC 165 ms 38256 KB
test_26_A.txt AC 205 ms 42476 KB
test_27_A.txt AC 204 ms 42604 KB
test_28_A.txt AC 207 ms 42604 KB
test_29_A.txt AC 209 ms 42732 KB
test_30_A.txt AC 205 ms 42732 KB
test_31_A.txt AC 206 ms 42604 KB
test_32_A.txt AC 176 ms 38896 KB
test_33_A.txt AC 222 ms 43628 KB
test_34_A.txt AC 181 ms 39280 KB
test_35_A.txt AC 196 ms 40560 KB
test_36_A.txt AC 180 ms 39280 KB
test_37_A.txt AC 202 ms 41452 KB
test_38_A.txt AC 165 ms 38256 KB
test_39_A.txt AC 168 ms 38256 KB
test_40_A.txt AC 166 ms 38256 KB
test_41_AB.txt AC 165 ms 38256 KB
test_42_A.txt AC 215 ms 43116 KB
test_43_A.txt AC 163 ms 38256 KB
test_44_A.txt AC 195 ms 40816 KB
test_45_A.txt AC 167 ms 38512 KB
test_46_A.txt AC 167 ms 38512 KB
test_47_AB.txt AC 161 ms 38256 KB
test_48_A.txt AC 179 ms 38896 KB
test_49_A.txt AC 167 ms 38512 KB
test_50_A.txt AC 163 ms 38256 KB
test_51_A.txt AC 164 ms 38384 KB