結果

問題 No.1340 おーじ君をさがせ
ユーザー chineristACchineristAC
提出日時 2021-01-15 21:49:38
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,423 bytes
コンパイル時間 1,348 ms
コンパイル使用メモリ 86,748 KB
実行使用メモリ 82,280 KB
最終ジャッジ日時 2023-08-17 19:44:52
合計ジャッジ時間 17,621 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,300 KB
testcase_01 AC 74 ms
71,228 KB
testcase_02 AC 78 ms
71,020 KB
testcase_03 AC 72 ms
70,980 KB
testcase_04 AC 72 ms
71,076 KB
testcase_05 AC 72 ms
71,072 KB
testcase_06 AC 71 ms
71,140 KB
testcase_07 AC 73 ms
71,300 KB
testcase_08 AC 72 ms
71,308 KB
testcase_09 AC 72 ms
70,812 KB
testcase_10 AC 89 ms
76,292 KB
testcase_11 AC 159 ms
77,260 KB
testcase_12 AC 125 ms
77,536 KB
testcase_13 AC 267 ms
78,116 KB
testcase_14 AC 215 ms
77,392 KB
testcase_15 AC 192 ms
77,328 KB
testcase_16 AC 121 ms
77,076 KB
testcase_17 AC 130 ms
77,396 KB
testcase_18 AC 153 ms
77,136 KB
testcase_19 AC 92 ms
76,516 KB
testcase_20 AC 94 ms
76,176 KB
testcase_21 AC 215 ms
77,980 KB
testcase_22 AC 1,397 ms
82,280 KB
testcase_23 AC 380 ms
77,660 KB
testcase_24 TLE -
testcase_25 AC 129 ms
77,448 KB
testcase_26 AC 126 ms
77,648 KB
testcase_27 AC 122 ms
77,516 KB
testcase_28 AC 133 ms
77,516 KB
testcase_29 AC 113 ms
77,500 KB
testcase_30 AC 228 ms
77,628 KB
testcase_31 AC 593 ms
78,540 KB
testcase_32 AC 400 ms
78,168 KB
testcase_33 AC 397 ms
78,468 KB
testcase_34 AC 611 ms
78,552 KB
testcase_35 AC 726 ms
78,832 KB
testcase_36 AC 76 ms
71,392 KB
testcase_37 AC 102 ms
77,004 KB
testcase_38 AC 417 ms
78,520 KB
testcase_39 AC 238 ms
77,824 KB
testcase_40 AC 225 ms
77,852 KB
testcase_41 AC 228 ms
77,728 KB
testcase_42 AC 81 ms
76,080 KB
testcase_43 AC 85 ms
76,632 KB
testcase_44 AC 88 ms
76,280 KB
testcase_45 AC 86 ms
76,332 KB
testcase_46 AC 294 ms
77,796 KB
testcase_47 AC 310 ms
77,968 KB
testcase_48 AC 337 ms
78,140 KB
testcase_49 AC 196 ms
77,572 KB
testcase_50 AC 208 ms
77,520 KB
testcase_51 AC 205 ms
77,592 KB
testcase_52 AC 235 ms
77,940 KB
testcase_53 AC 229 ms
77,692 KB
testcase_54 AC 233 ms
77,568 KB
testcase_55 AC 394 ms
78,284 KB
testcase_56 AC 84 ms
76,080 KB
testcase_57 AC 84 ms
75,956 KB
testcase_58 AC 78 ms
71,172 KB
testcase_59 AC 144 ms
77,672 KB
testcase_60 AC 76 ms
71,396 KB
testcase_61 AC 144 ms
77,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Matrix():
    mod=10**9+7

    def set_mod(m):
        Matrix.mod=m

    def __init__(self,L):
        self.row=len(L)
        self.column=len(L[0])
        self._matrix=L
        for i in range(self.row):
            for j in range(self.column):
                self._matrix[i][j]%=Matrix.mod

    def __getitem__(self,item):
        if type(item)==int:
            raise IndexError("you must specific row and column")
        elif len(item)!=2:
            raise IndexError("you must specific row and column")

        i,j=item
        return self._matrix[i][j]

    def __setitem__(self,item,val):
        if type(item)==int:
            raise IndexError("you must specific row and column")
        elif len(item)!=2:
            raise IndexError("you must specific row and column")

        i,j=item
        self._matrix[i][j]=val

    def __add__(self,other):
        if (self.row,self.column)!=(other.row,other.column):
            raise SizeError("sizes of matrixes are different")

        res=[[0 for j in range(self.column)] for i in range(self.row)]
        for i in range(self.row):
            for j in range(self.column):
                res[i][j]=self._matrix[i][j]+other._matrix[i][j]
                res[i][j]%=Matrix.mod
        return Matrix(res)

    def __sub__(self,other):
        if (self.row,self.column)!=(other.row,other.column):
            raise SizeError("sizes of matrixes are different")

        res=[[0 for j in range(self.column)] for i in range(self.row)]
        for i in range(self.row):
            for j in range(self.column):
                res[i][j]=self._matrix[i][j]-other._matrix[i][j]
                res[i][j]%=Matrix.mod
        return Matrix(res)

    def __mul__(self,other):
        if type(other)!=int:
            if self.column!=other.row:
                raise SizeError("sizes of matrixes are different")

            res=[[0 for j in range(other.column)] for i in range(self.row)]
            for i in range(self.row):
                for j in range(other.column):
                    temp=0
                    for k in range(self.column):
                        if self._matrix[i][k] and other._matrix[k][j]:
                            temp = 1
                    res[i][j]=temp
            return Matrix(res)
        else:
            n=other
            res=[[(n*self._matrix[i][j])%Matrix.mod for j in range(self.column)] for i in range(self.row)]
            return Matrix(res)

    def __pow__(self,m):
        if self.column!=self.row:
            raise MatrixPowError("the size of row must be the same as that of column")

        n=self.row
        res=Matrix([[int(i==j) for i in range(n)] for j in range(n)])
        while m:
            if m%2==1:
                res=res*self
            self=self*self
            m//=2
        return res

    def __str__(self):
        res=[]
        for i in range(self.row):
            for j in range(self.column):
                res.append(str(self._matrix[i][j]))
                res.append(" ")
            res.append("\n")
        res=res[:len(res)-1]
        return "".join(res)

N,M,T = map(int,input().split())
A = [[0 for j in range(N)] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    if not A[b][a]:
        A[b][a] = 1

A = Matrix(A)
A = A**T
B = [[1]] + [[0]] * (N-1)
B = Matrix(B)
A = A*B

res = 0
for i in range(N):
    if A[i,0]:
        res += 1

print(res)
0