結果
問題 | No.2713 Just Solitaire |
ユーザー | hato336 |
提出日時 | 2024-03-31 14:52:08 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 79 ms / 2,000 ms |
コード長 | 3,500 bytes |
コンパイル時間 | 135 ms |
コンパイル使用メモリ | 81,888 KB |
実行使用メモリ | 73,472 KB |
最終ジャッジ日時 | 2024-09-30 20:02:27 |
合計ジャッジ時間 | 2,789 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
54,924 KB |
testcase_01 | AC | 43 ms
56,184 KB |
testcase_02 | AC | 43 ms
56,444 KB |
testcase_03 | AC | 43 ms
56,716 KB |
testcase_04 | AC | 55 ms
69,132 KB |
testcase_05 | AC | 46 ms
62,684 KB |
testcase_06 | AC | 54 ms
69,244 KB |
testcase_07 | AC | 46 ms
63,664 KB |
testcase_08 | AC | 37 ms
54,928 KB |
testcase_09 | AC | 39 ms
56,648 KB |
testcase_10 | AC | 42 ms
62,852 KB |
testcase_11 | AC | 52 ms
65,000 KB |
testcase_12 | AC | 43 ms
61,104 KB |
testcase_13 | AC | 53 ms
67,700 KB |
testcase_14 | AC | 50 ms
66,236 KB |
testcase_15 | AC | 38 ms
56,220 KB |
testcase_16 | AC | 38 ms
55,520 KB |
testcase_17 | AC | 52 ms
68,508 KB |
testcase_18 | AC | 42 ms
56,960 KB |
testcase_19 | AC | 58 ms
70,892 KB |
testcase_20 | AC | 39 ms
56,188 KB |
testcase_21 | AC | 40 ms
55,608 KB |
testcase_22 | AC | 39 ms
55,844 KB |
testcase_23 | AC | 56 ms
68,072 KB |
testcase_24 | AC | 59 ms
70,968 KB |
testcase_25 | AC | 64 ms
73,192 KB |
testcase_26 | AC | 68 ms
70,528 KB |
testcase_27 | AC | 72 ms
72,576 KB |
testcase_28 | AC | 68 ms
70,784 KB |
testcase_29 | AC | 73 ms
71,936 KB |
testcase_30 | AC | 70 ms
71,424 KB |
testcase_31 | AC | 68 ms
70,656 KB |
testcase_32 | AC | 70 ms
71,680 KB |
testcase_33 | AC | 79 ms
73,472 KB |
ソースコード
from collections import deque class mf_graph: n=1 g=[[] for i in range(1)] pos=[] def __init__(self,N): self.n=N self.g=[[] for i in range(N)] self.pos=[] def add_edge(self,From,To,cap): assert 0<=From and From<self.n assert 0<=To and To<self.n assert 0<=cap m=len(self.pos) from_id=len(self.g[From]) self.pos.append([From,from_id]) to_id=len(self.g[To]) if From==To:to_id+=1 self.g[From].append([To,to_id,cap]) self.g[To].append([From,from_id,0]) return m def get_edge(self,i): m=len(self.pos) assert 0<=i and i<m _e=self.g[self.pos[i][0]][self.pos[i][1]] _re=self.g[_e[0]][_e[1]] return [self.pos[i][0],_e[0],_e[2]+_re[2],_re[2]] def edges(self): m=len(self.pos) result=[] for i in range(m): a,b,c,d=self.get_edge(i) result.append({"from":a,"to":b,"cap":c,"flow":d}) return result def change_edge(self,i,new_cap,new_flow): m=len(self.pos) assert 0<=i and i<m assert 0<=new_flow and new_flow<=new_cap _e=self.g[self.pos[i][0]][self.pos[i][1]] _re=self.g[_e[0]][_e[1]] _e[2]=new_cap-new_flow _re[2]=new_flow def flow(self,s,t,flow_limit=(1<<63)-1): assert 0<=s and s<self.n assert 0<=t and t<self.n assert s!=t def bfs(): level=[-1 for i in range(self.n)] level[s]=0 que=deque([]) que.append(s) while(que): v=que.popleft() for to,rev,cap in self.g[v]: if cap==0 or level[to]>=0:continue level[to]=level[v]+1 if to==t:return level que.append(to) return level def dfs(v,up): if (v==s):return up res=0 level_v=level[v] for i in range(Iter[v],len(self.g[v])): Iter[v]=i to,rev,cap=self.g[v][i] if (level_v<=level[to] or self.g[to][rev][2]==0):continue d=dfs(to,min(up-res,self.g[to][rev][2])) if d<=0:continue self.g[v][i][2]+=d self.g[to][rev][2]-=d res+=d if res==up:return res level[v]=self.n return res flow=0 while(flow<flow_limit): level=bfs() if level[t]==-1:break Iter=[0 for i in range(self.n)] f=dfs(t,flow_limit-flow) if not(f):break flow+=f return flow def min_cut(self,s): visited=[False for i in range(self.n)] que=deque([]) que.append(s) while(len(que)>0): p=que.popleft() visited[p]=True for to,rev,cap in self.g[p]: if cap and not(visited[to]): visited[to]=True que.append(to) return visited n,m = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) g = mf_graph(n+m+2) ans = 0 for i in range(m): q = list(map(int,input().split())) ans += b[i] g.add_edge(n+m,n+i,b[i]) g.add_edge(n+i,n+m+1,0) for k in range(1,len(q)): g.add_edge(n+i,q[k]-1,10**18) for i in range(n): g.add_edge(i,n+m+1,a[i]) print(-(g.flow(n+m,n+m+1,10**18) - ans))