結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | 👑 Kazun |
提出日時 | 2021-01-20 04:49:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 928 ms / 2,500 ms |
コード長 | 2,283 bytes |
コンパイル時間 | 332 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 188,584 KB |
最終ジャッジ日時 | 2024-12-29 09:02:11 |
合計ジャッジ時間 | 19,915 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
54,016 KB |
testcase_01 | AC | 49 ms
53,888 KB |
testcase_02 | AC | 46 ms
54,272 KB |
testcase_03 | AC | 46 ms
54,272 KB |
testcase_04 | AC | 46 ms
54,912 KB |
testcase_05 | AC | 45 ms
54,400 KB |
testcase_06 | AC | 48 ms
54,400 KB |
testcase_07 | AC | 46 ms
54,656 KB |
testcase_08 | AC | 149 ms
84,608 KB |
testcase_09 | AC | 107 ms
78,336 KB |
testcase_10 | AC | 143 ms
81,280 KB |
testcase_11 | AC | 146 ms
83,072 KB |
testcase_12 | AC | 146 ms
80,896 KB |
testcase_13 | AC | 548 ms
151,916 KB |
testcase_14 | AC | 611 ms
138,624 KB |
testcase_15 | AC | 613 ms
149,248 KB |
testcase_16 | AC | 480 ms
125,952 KB |
testcase_17 | AC | 329 ms
135,552 KB |
testcase_18 | AC | 928 ms
188,584 KB |
testcase_19 | AC | 797 ms
188,464 KB |
testcase_20 | AC | 801 ms
188,496 KB |
testcase_21 | AC | 795 ms
188,348 KB |
testcase_22 | AC | 788 ms
186,984 KB |
testcase_23 | AC | 284 ms
114,112 KB |
testcase_24 | AC | 128 ms
82,568 KB |
testcase_25 | AC | 434 ms
125,008 KB |
testcase_26 | AC | 588 ms
141,908 KB |
testcase_27 | AC | 399 ms
120,936 KB |
testcase_28 | AC | 373 ms
112,128 KB |
testcase_29 | AC | 346 ms
120,252 KB |
testcase_30 | AC | 347 ms
115,256 KB |
testcase_31 | AC | 305 ms
112,384 KB |
testcase_32 | AC | 283 ms
116,736 KB |
testcase_33 | AC | 624 ms
141,824 KB |
testcase_34 | AC | 732 ms
144,848 KB |
testcase_35 | AC | 865 ms
168,604 KB |
testcase_36 | AC | 837 ms
157,060 KB |
testcase_37 | AC | 283 ms
117,632 KB |
testcase_38 | AC | 234 ms
90,240 KB |
testcase_39 | AC | 226 ms
89,088 KB |
testcase_40 | AC | 222 ms
89,008 KB |
testcase_41 | AC | 223 ms
89,856 KB |
testcase_42 | AC | 221 ms
89,984 KB |
testcase_43 | AC | 319 ms
178,564 KB |
testcase_44 | AC | 271 ms
155,472 KB |
testcase_45 | AC | 315 ms
188,544 KB |
testcase_46 | AC | 150 ms
122,624 KB |
testcase_47 | AC | 43 ms
54,016 KB |
ソースコード
#SCC参考元:https://judge.yosupo.jp/submission/22487 def scc(E): n = len(E) iE = [[] for _ in range(n)] for i, e in enumerate(E): for v in e: iE[v].append(i) T = [] done = [0] * n # 0 -> 1 -> 2 ct = 0 for i0 in range(n): if done[i0]: continue Q = [~i0, i0] while Q: i = Q.pop() if i < 0: if done[~i] == 2: continue done[~i] = 2 T.append(~i) ct += 1 continue if i >= 0: if done[i]: continue done[i] = 1 for j in E[i]: if done[j]: continue Q.append(~j) Q.append(j) done = [0] * n SCC = [] for i0 in T[::-1]: if done[i0]: continue L = [] Q = [~i0, i0] while Q: i = Q.pop() if i < 0: if done[~i] == 2: continue done[~i] = 2 L.append(~i) continue if i >= 0: if done[i]: continue done[i] = 1 for j in iE[i]: if done[j]: continue Q.append(~j) Q.append(j) SCC.append(L) return SCC #================================================ import sys from collections import defaultdict input=sys.stdin.readline N,M=map(int,input().split()) Mod=10**9+7 X=[[] for _ in range(N+1)] E=[defaultdict(lambda :[0,0]) for _ in range(N+1)] for _ in range(M): u,v,w,a=map(int,input().split()) X[u].append(v) b,l=E[u][v] E[u][v]=[b+a,(l+a*w)%Mod] S=scc(X) inf=float("inf") Flag=[0]*(N+1) Flag[0]=1 DP=[[0,0] for _ in range(N+1)] DP[0]=[1,0] for U in S: if len(U)>=2: F=0 for v in U: F|=Flag[v] if F: for v in U: DP[v]=[inf,inf] for u in U: x,y=DP[u] for v in E[u]: Flag[v]|=Flag[u] if x==inf: DP[v]=[inf,inf] else: a,w=E[u][v] DP[v][0]+=x*a DP[v][1]+=y*a+x*w DP[v][0]%=Mod DP[v][1]%=Mod print(DP[N][1] if DP[N][1]<inf else "INF")