結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | mkawa2 |
提出日時 | 2021-10-29 17:45:03 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 2,203 ms / 2,500 ms |
コード長 | 2,882 bytes |
コンパイル時間 | 465 ms |
コンパイル使用メモリ | 13,184 KB |
実行使用メモリ | 143,040 KB |
最終ジャッジ日時 | 2024-06-23 11:37:48 |
合計ジャッジ時間 | 46,970 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
11,136 KB |
testcase_01 | AC | 31 ms
11,264 KB |
testcase_02 | AC | 30 ms
11,264 KB |
testcase_03 | AC | 32 ms
11,264 KB |
testcase_04 | AC | 31 ms
11,264 KB |
testcase_05 | AC | 31 ms
11,136 KB |
testcase_06 | AC | 31 ms
11,264 KB |
testcase_07 | AC | 32 ms
11,264 KB |
testcase_08 | AC | 111 ms
19,456 KB |
testcase_09 | AC | 63 ms
13,568 KB |
testcase_10 | AC | 107 ms
17,280 KB |
testcase_11 | AC | 99 ms
17,920 KB |
testcase_12 | AC | 102 ms
17,280 KB |
testcase_13 | AC | 1,467 ms
102,836 KB |
testcase_14 | AC | 1,650 ms
112,312 KB |
testcase_15 | AC | 1,813 ms
118,188 KB |
testcase_16 | AC | 1,223 ms
85,884 KB |
testcase_17 | AC | 831 ms
70,364 KB |
testcase_18 | AC | 2,203 ms
142,908 KB |
testcase_19 | AC | 2,198 ms
142,904 KB |
testcase_20 | AC | 2,180 ms
142,908 KB |
testcase_21 | AC | 2,161 ms
143,036 KB |
testcase_22 | AC | 2,178 ms
143,040 KB |
testcase_23 | AC | 508 ms
45,424 KB |
testcase_24 | AC | 278 ms
25,216 KB |
testcase_25 | AC | 716 ms
50,664 KB |
testcase_26 | AC | 1,077 ms
67,968 KB |
testcase_27 | AC | 814 ms
55,680 KB |
testcase_28 | AC | 537 ms
41,168 KB |
testcase_29 | AC | 786 ms
55,680 KB |
testcase_30 | AC | 553 ms
41,240 KB |
testcase_31 | AC | 541 ms
45,428 KB |
testcase_32 | AC | 621 ms
46,592 KB |
testcase_33 | AC | 1,035 ms
64,640 KB |
testcase_34 | AC | 1,102 ms
69,468 KB |
testcase_35 | AC | 1,517 ms
99,612 KB |
testcase_36 | AC | 1,389 ms
87,408 KB |
testcase_37 | AC | 631 ms
42,752 KB |
testcase_38 | AC | 1,442 ms
81,664 KB |
testcase_39 | AC | 1,445 ms
81,664 KB |
testcase_40 | AC | 1,466 ms
81,536 KB |
testcase_41 | AC | 1,452 ms
81,664 KB |
testcase_42 | AC | 1,447 ms
81,536 KB |
testcase_43 | AC | 1,016 ms
101,900 KB |
testcase_44 | AC | 925 ms
90,912 KB |
testcase_45 | AC | 510 ms
52,636 KB |
testcase_46 | AC | 454 ms
58,056 KB |
testcase_47 | AC | 31 ms
11,136 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (1, 0), (0, -1), (-1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 1 << 63 # md = 998244353 md = 10**9+7 # 各強連結成分をリストにしてトポロジカル順に返す def SCC(to, ot): n = len(to) # トポロジカルソート fin = [-1]*n topo = [] for u in range(n): if fin[u] != -1: continue stack = [u] while stack: u = stack[-1] if fin[u] == -1: fin[u] = 0 for v, _, _ in to[u]: if fin[v] != -1: continue stack.append(v) else: stack.pop() if fin[u] == 0: fin[u] = 1 topo.append(u) # 逆辺でdfs res = [] while topo: u = topo.pop() if fin[u] != 1: continue fin[u] = 2 cur = [u] i = 0 while i < len(cur): u = cur[i] for v, _, _ in ot[u]: if fin[v] == 2: continue fin[v] = 2 cur.append(v) i += 1 res.append(cur) return res n, m = LI() to = [[] for _ in range(n+1)] ot = [[] for _ in range(n+1)] for i in range(m): u, v, l, a = LI() to[u].append((v, l, a)) ot[v].append((u, l, a)) gg = SCC(to, ot) gn = len(gg) # print(gg) utog = [-1]*(n+1) for g, uu in enumerate(gg): for u in uu: utog[u] = g # print(utog) to2 = [[] for _ in range(gn)] ot2 = [[] for _ in range(gn)] for u in range(n+1): g = utog[u] for v, l, a in to[u]: h = utog[v] if g == h: continue to2[g].append((h, l, a)) ot2[h].append((g, l, a)) # print(to2, ot2) def reach(g, to): res = [False]*gn res[g] = True stack = [g] while stack: g = stack.pop() for h, _, _ in to[g]: if res[h]: continue res[h] = True stack.append(h) return res s = utog[0] t = utog[n] r1 = reach(s, to2) r2 = reach(t, ot2) # print(r1, r2) for g in range(gn): if r1[g] and r2[g] and len(gg[g]) > 1: print("INF") exit() dd = [0]*gn cc = [0]*gn cc[t] = 1 for g in range(t-1, s-1, -1): for h, l, a in to2[g]: cc[g] += cc[h]*a%md dd[g] += (dd[h]+l*cc[h]%md)%md*a%md cc[g] %= md dd[g] %= md print(dd[s])