Submission #1766489


Source Code Expand

from sys import stdin
def IL():return list(map(int, stdin.readline().split()))


class Dinic:
	def __init__(self, v, inf=float("inf")):
		self.V = v
		self.inf = inf
		self.G = [[] for _ in range(v)]
		self.level = [0 for _ in range(v)]
		self.iter = [0 for _ in range(v)]

	def addEdge(self, fm, to, cap):
		'''
		to:行き先
		cap:容量
		rev:反対側の辺
		'''
		self.G[fm].append({'to':to, 'cap':cap, 'rev':len(self.G[to])})
		self.G[to].append({'to':fm, 'cap':0, 'rev':len(self.G[fm])-1})


	# sからの最短距離をbfsで計算
	def bfs(self, s):
	    import queue
	    
	    self.level = [-1 for _ in range(self.V)]
	    self.level[s] = 0
	    que = queue.Queue()
	    que.put(s)
	    while not que.empty():
        	v = que.get()
        	for i in range(len(self.G[v])):
        		e = self.G[v][i]
        		if e['cap'] > 0 and self.level[e['to']] < 0:
        			self.level[e['to']] = self.level[v] + 1
        			que.put(e['to'])


	def dfs(self, v, t, f):
		if v == t: return f
		for i in range(self.iter[v], len(self.G[v])):
			self.iter[v] = i
			e = self.G[v][i]
			if e['cap'] > 0 and self.level[v] < self.level[e['to']]:
				d = self.dfs(e['to'], t ,min(f,e['cap']))
				if d > 0:
					e['cap'] -= d
					self.G[e['to']][e['rev']]['cap'] += d
					return d
		return 0


	def max_flow(self,s,t):
		flow = 0
		while True:
			self.bfs(s)
			if self.level[t] < 0: return flow
			self.iter = [0 for _ in range(self.V)]
			f = self.dfs(s,t,self.inf)
			while f > 0:
				flow += f
				f = self.dfs(s,t,self.inf)

def main():
    N,G,E = IL()
    p = IL()
    d = Dinic(102)
    
    for i in range(E):
        a,b = IL()
        d.addEdge(a,b,1)
        d.addEdge(b,a,1)
        
    for i in p:
	    d.addEdge(i,N,1)
	    d.addEdge(N,i,1)
    
    print(d.max_flow(0,N))
    
    
if __name__ == "__main__": main()

Submission Info

Submission Time
Task D - 浮気予防
User yk16
Language Python (3.4.3)
Score 100
Code Size 1915 Byte
Status AC
Exec Time 63 ms
Memory 10224 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 40 ms 4336 KB
sample_02.txt AC 26 ms 3952 KB
sample_03.txt AC 26 ms 3952 KB
sample_04.txt AC 26 ms 3952 KB
sample_05.txt AC 26 ms 3936 KB
test_01_AB.txt AC 26 ms 3952 KB
test_02_AB.txt AC 26 ms 3952 KB
test_03_AB.txt AC 26 ms 3952 KB
test_04_AB.txt AC 26 ms 3952 KB
test_05_AB.txt AC 27 ms 4080 KB
test_06_AB.txt AC 26 ms 3952 KB
test_07_AB.txt AC 26 ms 3952 KB
test_08_AB.txt AC 26 ms 3952 KB
test_09_AB.txt AC 26 ms 4020 KB
test_10_AB.txt AC 26 ms 4080 KB
test_11_AB.txt AC 26 ms 3952 KB
test_12_AB.txt AC 26 ms 3952 KB
test_13_AB.txt AC 26 ms 3952 KB
test_14_AB.txt AC 26 ms 3948 KB
test_15_AB.txt AC 26 ms 3944 KB
test_16_AB.txt AC 26 ms 3944 KB
test_17_AB.txt AC 26 ms 4080 KB
test_18_AB.txt AC 26 ms 3952 KB
test_19_AB.txt AC 26 ms 4080 KB
test_20_AB.txt AC 26 ms 3912 KB
test_21_AB.txt AC 26 ms 4080 KB
test_22_AB.txt AC 26 ms 3952 KB
test_23_AB.txt AC 26 ms 3952 KB
test_24_AB.txt AC 26 ms 3952 KB
test_25_AB.txt AC 26 ms 4072 KB
test_26_A.txt AC 58 ms 10224 KB
test_27_A.txt AC 62 ms 10224 KB
test_28_A.txt AC 62 ms 10212 KB
test_29_A.txt AC 61 ms 10096 KB
test_30_A.txt AC 61 ms 10088 KB
test_31_A.txt AC 63 ms 10212 KB
test_32_A.txt AC 30 ms 4840 KB
test_33_A.txt AC 50 ms 6956 KB
test_34_A.txt AC 30 ms 4412 KB
test_35_A.txt AC 37 ms 5232 KB
test_36_A.txt AC 32 ms 4668 KB
test_37_A.txt AC 39 ms 6000 KB
test_38_A.txt AC 27 ms 4080 KB
test_39_A.txt AC 26 ms 4068 KB
test_40_A.txt AC 26 ms 3944 KB
test_41_AB.txt AC 26 ms 3912 KB
test_42_A.txt AC 46 ms 6512 KB
test_43_A.txt AC 27 ms 4080 KB
test_44_A.txt AC 35 ms 5104 KB
test_45_A.txt AC 27 ms 4200 KB
test_46_A.txt AC 27 ms 4208 KB
test_47_AB.txt AC 26 ms 3952 KB
test_48_A.txt AC 28 ms 4200 KB
test_49_A.txt AC 28 ms 4200 KB
test_50_A.txt AC 26 ms 4068 KB
test_51_A.txt AC 26 ms 4080 KB