結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー merlinmerlin
提出日時 2021-11-19 22:32:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,619 ms / 2,000 ms
コード長 1,525 bytes
コンパイル時間 4,114 ms
コンパイル使用メモリ 73,704 KB
実行使用メモリ 53,128 KB
最終ジャッジ日時 2023-08-30 09:19:29
合計ジャッジ時間 23,468 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,168 KB
testcase_01 AC 43 ms
49,240 KB
testcase_02 AC 43 ms
49,292 KB
testcase_03 AC 44 ms
49,360 KB
testcase_04 AC 135 ms
53,128 KB
testcase_05 AC 43 ms
49,612 KB
testcase_06 AC 44 ms
49,608 KB
testcase_07 AC 45 ms
49,504 KB
testcase_08 AC 351 ms
52,124 KB
testcase_09 AC 350 ms
52,240 KB
testcase_10 AC 353 ms
52,168 KB
testcase_11 AC 313 ms
52,980 KB
testcase_12 AC 390 ms
52,760 KB
testcase_13 AC 374 ms
52,968 KB
testcase_14 AC 1,544 ms
52,768 KB
testcase_15 AC 1,587 ms
52,848 KB
testcase_16 AC 1,593 ms
52,856 KB
testcase_17 AC 1,575 ms
52,036 KB
testcase_18 AC 1,619 ms
52,104 KB
testcase_19 AC 1,556 ms
52,248 KB
testcase_20 AC 1,102 ms
52,128 KB
testcase_21 AC 1,289 ms
52,248 KB
testcase_22 AC 303 ms
53,068 KB
testcase_23 AC 1,503 ms
52,268 KB
testcase_24 AC 241 ms
52,024 KB
testcase_25 AC 470 ms
52,012 KB
testcase_26 AC 204 ms
52,180 KB
testcase_27 AC 51 ms
50,096 KB
testcase_28 AC 77 ms
51,800 KB
testcase_29 AC 49 ms
49,460 KB
testcase_30 AC 298 ms
52,972 KB
testcase_31 AC 294 ms
53,020 KB
testcase_32 AC 280 ms
52,996 KB
testcase_33 AC 280 ms
52,928 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];
        dp[0][0]=1;
        multiply(dp,ans);
        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;
        }

        //in out problem n==m==k
        for(i=0;i<n;i++)
        for(j=0;j<l;j++)
        a[i][j]=temp[i][j];
    }

    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