結果
問題 | No.650 行列木クエリ |
ユーザー | konsin_tokage |
提出日時 | 2018-03-01 23:14:28 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 885 bytes |
コンパイル時間 | 365 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 105,856 KB |
最終ジャッジ日時 | 2024-06-07 17:33:18 |
合計ジャッジ時間 | 8,457 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
57,984 KB |
testcase_01 | AC | 239 ms
81,940 KB |
testcase_02 | AC | 354 ms
101,732 KB |
testcase_03 | AC | 38 ms
52,096 KB |
testcase_04 | AC | 227 ms
82,508 KB |
testcase_05 | AC | 382 ms
102,016 KB |
testcase_06 | AC | 38 ms
51,968 KB |
testcase_07 | AC | 38 ms
51,840 KB |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | -- | - |
ソースコード
n = int(input()) graph = [[] for _ in range(n)] for i in range(n-1): a, b = map(int, input().split()) graph[a].append((i,b)) graph[b].append((i,a)) edge = [0]*(n-1) parent = [0]*n bfs = [0] for i in range(n): u = bfs[i] for e, v in graph[u]: if v == parent[u]: continue parent[v] = u edge[e] = v bfs.append(v) def mul(x, y): a = (x[0]*y[0]+x[1]*y[2])%(10**9+7) b = (x[0]*y[1]+x[1]*y[3])%(10**9+7) c = (x[2]*y[0]+x[3]*y[2])%(10**9+7) d = (x[2]*y[1]+x[3]*y[3])%(10**9+7) return (a,b,c,d) mat = [(1,0,0,1)]*n for _ in range(int(input())): a = input().split() if a[0] == 'x': i, *x = map(int, a[1:]) mat[edge[i]] = x else: i, j = map(int, a[1:]) c = mat[j] while i != parent[j]: j = parent[j] c = mul(mat[j], c) print(*c)