解题思路:
注意事项:
参考代码:
n,m = map(int,input().split())
op = [3,4,5,0,1,2]
clash = [[4 for i in range(6)] for i in range(6)]
mod = 10**9 + 7
for i in range(m):
a,b = map(int,input().split())
a -= 1
b -= 1
clash[a][op[b]] = 0
clash[b][op[a]] = 0
def mmul(a,b):
c = [[0 for i in range(len(b))]for i in range(len(a))]
for i in range(len(a)):
for j in range(len(b)):
for k in range(len(b)):
c[i][j] = (c[i][j] + a[i][k]*b[k][j]) % mod
return c
def mpow(a,x):
b = [[0 for i in range(len(a))]for i in range(len(a))]
for i in range(len(a)):
b[i][i] = 1
while x:
if x & 1:
b = mmul(b,a)
a = mmul(a,a)
x >>= 1
return b
print(sum(mmul([[4,4,4,4,4,4]],mpow(clash,n-1))[0])%mod)
0.0分
5 人评分