結果

問題 No.1340 おーじ君をさがせ
ユーザー chineristACchineristAC
提出日時 2021-01-15 21:47:23
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,394 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 84,480 KB
最終ジャッジ日時 2024-05-05 02:38:53
合計ジャッジ時間 17,323 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,992 KB
testcase_01 AC 37 ms
52,608 KB
testcase_02 AC 41 ms
52,352 KB
testcase_03 AC 38 ms
52,736 KB
testcase_04 AC 37 ms
52,992 KB
testcase_05 AC 36 ms
52,608 KB
testcase_06 AC 37 ms
52,864 KB
testcase_07 AC 39 ms
52,992 KB
testcase_08 AC 37 ms
52,864 KB
testcase_09 AC 36 ms
52,480 KB
testcase_10 AC 63 ms
69,248 KB
testcase_11 AC 151 ms
76,416 KB
testcase_12 AC 78 ms
73,216 KB
testcase_13 AC 279 ms
77,312 KB
testcase_14 AC 240 ms
76,672 KB
testcase_15 AC 210 ms
76,416 KB
testcase_16 AC 73 ms
72,064 KB
testcase_17 AC 120 ms
75,904 KB
testcase_18 AC 159 ms
76,288 KB
testcase_19 AC 62 ms
67,840 KB
testcase_20 AC 55 ms
64,384 KB
testcase_21 AC 364 ms
78,464 KB
testcase_22 AC 1,322 ms
81,920 KB
testcase_23 AC 371 ms
78,336 KB
testcase_24 TLE -
testcase_25 AC 104 ms
76,416 KB
testcase_26 AC 97 ms
76,544 KB
testcase_27 AC 94 ms
76,416 KB
testcase_28 AC 123 ms
76,800 KB
testcase_29 AC 94 ms
76,160 KB
testcase_30 AC 422 ms
78,848 KB
testcase_31 AC 1,765 ms
83,968 KB
testcase_32 AC 500 ms
77,440 KB
testcase_33 AC 502 ms
77,696 KB
testcase_34 AC 554 ms
79,232 KB
testcase_35 AC 652 ms
80,640 KB
testcase_36 AC 38 ms
53,120 KB
testcase_37 AC 70 ms
73,600 KB
testcase_38 AC 531 ms
77,184 KB
testcase_39 AC 206 ms
77,312 KB
testcase_40 AC 211 ms
77,056 KB
testcase_41 AC 205 ms
76,928 KB
testcase_42 AC 44 ms
60,416 KB
testcase_43 AC 44 ms
60,288 KB
testcase_44 AC 54 ms
64,256 KB
testcase_45 AC 47 ms
61,568 KB
testcase_46 AC 195 ms
77,568 KB
testcase_47 AC 230 ms
77,952 KB
testcase_48 AC 225 ms
78,080 KB
testcase_49 AC 177 ms
76,288 KB
testcase_50 AC 190 ms
76,288 KB
testcase_51 AC 177 ms
76,672 KB
testcase_52 AC 267 ms
76,288 KB
testcase_53 AC 283 ms
76,544 KB
testcase_54 AC 279 ms
76,544 KB
testcase_55 AC 277 ms
77,824 KB
testcase_56 AC 54 ms
61,440 KB
testcase_57 WA -
testcase_58 AC 44 ms
53,248 KB
testcase_59 AC 140 ms
76,032 KB
testcase_60 AC 39 ms
52,992 KB
testcase_61 WA -
権限があれば一括ダウンロードができます

ソースコード

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):
                        temp+=self._matrix[i][k]*other._matrix[k][j]
                    res[i][j]=temp%Matrix.mod
            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