結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | 👑 Kazun |
提出日時 | 2021-01-20 04:49:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 864 ms / 2,500 ms |
コード長 | 2,283 bytes |
コンパイル時間 | 480 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 188,708 KB |
最終ジャッジ日時 | 2024-06-09 06:30:22 |
合計ジャッジ時間 | 20,492 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
53,760 KB |
testcase_01 | AC | 43 ms
54,144 KB |
testcase_02 | AC | 46 ms
54,016 KB |
testcase_03 | AC | 44 ms
54,272 KB |
testcase_04 | AC | 48 ms
55,040 KB |
testcase_05 | AC | 42 ms
54,272 KB |
testcase_06 | AC | 45 ms
54,912 KB |
testcase_07 | AC | 48 ms
54,400 KB |
testcase_08 | AC | 155 ms
84,480 KB |
testcase_09 | AC | 106 ms
78,208 KB |
testcase_10 | AC | 148 ms
81,364 KB |
testcase_11 | AC | 149 ms
83,120 KB |
testcase_12 | AC | 153 ms
80,896 KB |
testcase_13 | AC | 578 ms
151,788 KB |
testcase_14 | AC | 675 ms
138,644 KB |
testcase_15 | AC | 683 ms
149,424 KB |
testcase_16 | AC | 519 ms
125,600 KB |
testcase_17 | AC | 338 ms
135,792 KB |
testcase_18 | AC | 844 ms
188,708 KB |
testcase_19 | AC | 843 ms
188,516 KB |
testcase_20 | AC | 837 ms
188,616 KB |
testcase_21 | AC | 837 ms
188,244 KB |
testcase_22 | AC | 835 ms
186,732 KB |
testcase_23 | AC | 320 ms
113,964 KB |
testcase_24 | AC | 122 ms
82,588 KB |
testcase_25 | AC | 493 ms
125,128 KB |
testcase_26 | AC | 648 ms
142,220 KB |
testcase_27 | AC | 436 ms
121,324 KB |
testcase_28 | AC | 378 ms
112,208 KB |
testcase_29 | AC | 391 ms
120,376 KB |
testcase_30 | AC | 371 ms
115,164 KB |
testcase_31 | AC | 329 ms
112,380 KB |
testcase_32 | AC | 302 ms
116,400 KB |
testcase_33 | AC | 654 ms
141,716 KB |
testcase_34 | AC | 724 ms
144,844 KB |
testcase_35 | AC | 864 ms
168,612 KB |
testcase_36 | AC | 806 ms
157,692 KB |
testcase_37 | AC | 274 ms
117,632 KB |
testcase_38 | AC | 238 ms
89,960 KB |
testcase_39 | AC | 245 ms
88,704 KB |
testcase_40 | AC | 235 ms
89,216 KB |
testcase_41 | AC | 244 ms
89,948 KB |
testcase_42 | AC | 236 ms
89,936 KB |
testcase_43 | AC | 326 ms
178,820 KB |
testcase_44 | AC | 277 ms
155,348 KB |
testcase_45 | AC | 322 ms
188,584 KB |
testcase_46 | AC | 166 ms
122,716 KB |
testcase_47 | AC | 43 ms
54,316 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")