結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | ophhdn |
提出日時 | 2021-08-08 12:44:48 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,882 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 82,400 KB |
実行使用メモリ | 133,632 KB |
最終ジャッジ日時 | 2024-09-19 08:20:39 |
合計ジャッジ時間 | 15,504 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 91 ms
80,512 KB |
testcase_01 | AC | 86 ms
80,640 KB |
testcase_02 | AC | 91 ms
80,512 KB |
testcase_03 | AC | 93 ms
80,512 KB |
testcase_04 | AC | 95 ms
80,512 KB |
testcase_05 | AC | 91 ms
80,640 KB |
testcase_06 | AC | 92 ms
80,768 KB |
testcase_07 | AC | 91 ms
80,384 KB |
testcase_08 | AC | 134 ms
84,608 KB |
testcase_09 | AC | 125 ms
81,536 KB |
testcase_10 | AC | 131 ms
83,964 KB |
testcase_11 | AC | 137 ms
84,096 KB |
testcase_12 | AC | 126 ms
83,712 KB |
testcase_13 | AC | 397 ms
118,784 KB |
testcase_14 | AC | 495 ms
117,888 KB |
testcase_15 | AC | 475 ms
123,520 KB |
testcase_16 | AC | 421 ms
108,672 KB |
testcase_17 | AC | 247 ms
108,800 KB |
testcase_18 | AC | 568 ms
131,200 KB |
testcase_19 | AC | 597 ms
133,632 KB |
testcase_20 | AC | 591 ms
133,632 KB |
testcase_21 | AC | 566 ms
130,944 KB |
testcase_22 | AC | 574 ms
130,816 KB |
testcase_23 | AC | 181 ms
92,160 KB |
testcase_24 | AC | 156 ms
89,344 KB |
testcase_25 | AC | 256 ms
99,840 KB |
testcase_26 | AC | 320 ms
108,328 KB |
testcase_27 | AC | 261 ms
101,248 KB |
testcase_28 | AC | 197 ms
95,104 KB |
testcase_29 | AC | 257 ms
100,864 KB |
testcase_30 | AC | 198 ms
94,720 KB |
testcase_31 | AC | 188 ms
93,428 KB |
testcase_32 | AC | 224 ms
97,152 KB |
testcase_33 | AC | 327 ms
104,712 KB |
testcase_34 | AC | 330 ms
105,728 KB |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | AC | 208 ms
99,968 KB |
testcase_38 | AC | 410 ms
112,256 KB |
testcase_39 | AC | 343 ms
112,384 KB |
testcase_40 | AC | 284 ms
112,384 KB |
testcase_41 | AC | 286 ms
112,384 KB |
testcase_42 | AC | 292 ms
112,384 KB |
testcase_43 | AC | 204 ms
115,968 KB |
testcase_44 | AC | 221 ms
119,680 KB |
testcase_45 | AC | 169 ms
97,920 KB |
testcase_46 | AC | 139 ms
110,336 KB |
testcase_47 | WA | - |
ソースコード
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce import pprint sys.setrecursionlimit(10 ** 9) INF = 10 ** 20 def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10**9+7 n,m=LI() G=[[]for _ in range(n+1)] for _ in range(m): u,v,l,a=LI() G[u]+=[(v,l,a)] def topological_sort(G): n = len(G) in_degree = [0] * n for u in range(n): for v,_,_ in G[u]: in_degree[v] += 1 topological_order = [] que = deque() for i in range(n): if in_degree[i] == 0: que += [i] while que: u = que.pop() topological_order += [u] for v,_,_ in G[u]: in_degree[v] -= 1 if in_degree[v] == 0: que += [v] return topological_order q=deque([0]) D=[0]*(n+1) D2=[0]*(n+1) D2[0]=1 D[0]=0 order=topological_sort(G) if len(order)!=n+1: print("INF") exit() s=set() for ui in order: s.add(ui) for vi,li,ai in G[ui]: D[vi]+=(D[ui]+D2[ui]*li)*ai%mod D[vi]%=mod D2[vi]+=D2[ui]*ai D2[vi]%=mod print(D[n])