結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー merlinmerlin
提出日時 2021-11-19 22:35:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,629 ms / 2,000 ms
コード長 1,626 bytes
コンパイル時間 3,540 ms
コンパイル使用メモリ 73,508 KB
実行使用メモリ 52,912 KB
最終ジャッジ日時 2023-08-30 09:22:36
合計ジャッジ時間 23,559 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,224 KB
testcase_01 AC 44 ms
49,492 KB
testcase_02 AC 46 ms
49,200 KB
testcase_03 AC 45 ms
49,088 KB
testcase_04 AC 140 ms
52,876 KB
testcase_05 AC 44 ms
49,272 KB
testcase_06 AC 45 ms
49,332 KB
testcase_07 AC 45 ms
49,308 KB
testcase_08 AC 352 ms
52,124 KB
testcase_09 AC 355 ms
51,976 KB
testcase_10 AC 356 ms
51,892 KB
testcase_11 AC 310 ms
52,660 KB
testcase_12 AC 396 ms
52,832 KB
testcase_13 AC 377 ms
52,768 KB
testcase_14 AC 1,562 ms
52,584 KB
testcase_15 AC 1,588 ms
52,908 KB
testcase_16 AC 1,597 ms
52,696 KB
testcase_17 AC 1,587 ms
52,044 KB
testcase_18 AC 1,629 ms
52,204 KB
testcase_19 AC 1,571 ms
51,808 KB
testcase_20 AC 1,112 ms
51,928 KB
testcase_21 AC 1,299 ms
49,968 KB
testcase_22 AC 307 ms
52,832 KB
testcase_23 AC 1,517 ms
52,188 KB
testcase_24 AC 245 ms
51,788 KB
testcase_25 AC 477 ms
52,212 KB
testcase_26 AC 220 ms
52,148 KB
testcase_27 AC 53 ms
49,844 KB
testcase_28 AC 78 ms
51,760 KB
testcase_29 AC 53 ms
49,136 KB
testcase_30 AC 305 ms
52,692 KB
testcase_31 AC 290 ms
52,544 KB
testcase_32 AC 288 ms
52,632 KB
testcase_33 AC 282 ms
52,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        int n=Integer.parseInt(s[0]),m=Integer.parseInt(s[1]); long t=Long.parseLong(s[2]);
        int i; long a[][]=new long[n][n];
        for(i=0;i<m;i++)
        {
            s=bu.readLine().split(" ");
            int u=Integer.parseInt(s[0]),v=Integer.parseInt(s[1]);
            a[u][v]=a[v][u]=1;
        }

        long ans[][]=power(a,t),dp[][]=new long[1][n];  //multiply the input graph t times, to get final sequence(matrix exponentiation)
        dp[0][0]=1;
        multiply(dp,ans);   //find ans from it
        System.out.println(dp[0][0]);
    }

    static long temp[][]=new long[100][100],M=998244353;
    static void multiply(long a[][],long b[][])
    {
        int i,j,k,n=a.length,m=a[0].length,l=b[0].length;
        for(i=0;i<n;i++)
        for(j=0;j<l;j++)
        {
            temp[i][j]=0;
            for(k=0;k<m;k++)
            temp[i][j]=(temp[i][j]+a[i][k]*b[k][j])%M;
        }

        for(i=0;i<n;i++)
        for(j=0;j<l;j++)
        a[i][j]=temp[i][j]; //1st matrix will store result
    }

    static long[][] power(long a[][],long b)
    {
        int i,n=a.length;
        long res[][]=new long[n][n];
        for(i=0;i<n;i++) res[i][i]=1;
        while(b!=0)
        {
            if(b%2==1) multiply(res,a);
            b>>=1;
            multiply(a,a);
        }
        return res;
    }
}
0