import sequtils template times*(n:int,body) = (for _ in 0.. 0: let v = q.dequeue() for e in G[v]: if e.cap <= 0 : continue if level[e.dst] >= 0 : continue level[e.dst] = level[v] + 1 q.enqueue(e.dst) # 増加パスを探索 proc dfs(G:var Graph,src,dst,flow:int):int = if src == dst : return flow for i in iter[src]..= level[e.dst] : continue let d = G.dfs(e.dst,dst,flow.min(e.cap)) if d <= 0 : continue G[src][i].cap -= d G[e.dst][e.rev].cap += d return d return 0 while true: G.bfs(src) if level[dst] < 0 : return iter = newSeq[int](G.len) while true: let f = G.dfs(src,dst,1e10.int) if f <= 0 : break result += f useMaxFlow() proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} proc scan(): int = while true: let k = getchar_unlocked() if k < '0': return result = 10 * result + k.ord - '0'.ord let w = scan() let n = scan() let J = newSeqWith(n,scan()) let m = scan() let C = newSeqWith(m,scan()) var f = initFlow(n+m+2) # J:0.. n+m+1 let src = n + m let dst = n + m + 1 for i,j in J: f.add(src,i,j) for i,c in C: f.add(n+i,dst,c) for c in n..