結果
| 問題 | No.650 行列木クエリ |
| コンテスト | |
| ユーザー |
skii
|
| 提出日時 | 2018-02-28 12:34:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 861 bytes |
| コンパイル時間 | 269 ms |
| コンパイル使用メモリ | 82,228 KB |
| 実行使用メモリ | 97,548 KB |
| 最終ジャッジ日時 | 2024-12-17 19:25:13 |
| 合計ジャッジ時間 | 2,497 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 RE * 2 |
ソースコード
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))
parents = [0]*n
edges = [0]*(n-1)
def dfs(u, p):
parents[u] = p
for i, v in graph[u]:
if v == p:
continue
edges[i] = v
dfs(v, u)
dfs(0, 0)
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)
mats = [(1,0,0,1)]*n
for _ in range(int(input())):
a = input().split()
if a[0] == 'x':
i, *x = map(int, a[1:])
mats[edges[i]] = x
else:
i, j = map(int, a[1:])
c = mats[j]
while i != parents[j]:
j = parents[j]
c = mul(mats[j], c)
print(*c)
skii