結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | mkawa2 |
提出日時 | 2021-10-29 16:13:44 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,992 bytes |
コンパイル時間 | 181 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 218,996 KB |
最終ジャッジ日時 | 2024-10-07 08:35:25 |
合計ジャッジ時間 | 23,580 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,992 KB |
testcase_01 | AC | 39 ms
52,352 KB |
testcase_02 | AC | 40 ms
52,736 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 278 ms
112,632 KB |
testcase_24 | AC | 133 ms
90,856 KB |
testcase_25 | AC | 381 ms
115,800 KB |
testcase_26 | AC | 537 ms
134,144 KB |
testcase_27 | AC | 398 ms
122,528 KB |
testcase_28 | AC | 314 ms
103,680 KB |
testcase_29 | AC | 375 ms
123,084 KB |
testcase_30 | AC | 326 ms
104,320 KB |
testcase_31 | AC | 304 ms
103,520 KB |
testcase_32 | AC | 301 ms
115,072 KB |
testcase_33 | AC | 488 ms
132,988 KB |
testcase_34 | AC | 603 ms
131,556 KB |
testcase_35 | AC | 706 ms
161,508 KB |
testcase_36 | AC | 651 ms
143,020 KB |
testcase_37 | AC | 260 ms
122,184 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 341 ms
167,464 KB |
testcase_44 | AC | 325 ms
164,556 KB |
testcase_45 | AC | 226 ms
125,532 KB |
testcase_46 | AC | 106 ms
104,084 KB |
testcase_47 | RE | - |
ソースコード
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 r1 = reach(utog[0], to2) r2 = reach(utog[n], ot2) # print(r1, r2) cnt = [] for c0, c1 in zip(r1, r2): cnt.append(c0+c1) for g in range(gn): if cnt[g] < 2: continue if len(gg[g]) > 1: print("INF") exit() ss = [0]*gn cc = [0]*gn g = utog[n] cc[g] = 1 for g in range(utog[n], utog[0]-1, -1): if cnt[g] < 2: continue for h, l, a in to[g]: c = cc[h]*a%md cc[g] += c ss[g] += c*l%md+ss[h] cc[g] %= md ss[g] %= md print(ss[utog[0]])