結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー tentententen
提出日時 2021-11-22 10:21:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 488 ms / 2,000 ms
コード長 2,433 bytes
コンパイル時間 1,945 ms
コンパイル使用メモリ 76,416 KB
実行使用メモリ 58,704 KB
最終ジャッジ日時 2023-09-06 01:02:35
合計ジャッジ時間 12,506 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,432 KB
testcase_01 AC 42 ms
49,716 KB
testcase_02 AC 42 ms
49,404 KB
testcase_03 AC 41 ms
49,488 KB
testcase_04 AC 162 ms
53,996 KB
testcase_05 AC 41 ms
49,380 KB
testcase_06 AC 41 ms
49,572 KB
testcase_07 AC 40 ms
49,472 KB
testcase_08 AC 463 ms
58,380 KB
testcase_09 AC 452 ms
58,140 KB
testcase_10 AC 455 ms
58,280 KB
testcase_11 AC 486 ms
58,336 KB
testcase_12 AC 488 ms
57,864 KB
testcase_13 AC 477 ms
58,328 KB
testcase_14 AC 479 ms
58,484 KB
testcase_15 AC 478 ms
58,408 KB
testcase_16 AC 468 ms
58,500 KB
testcase_17 AC 466 ms
58,704 KB
testcase_18 AC 449 ms
58,252 KB
testcase_19 AC 456 ms
58,192 KB
testcase_20 AC 364 ms
58,276 KB
testcase_21 AC 382 ms
58,276 KB
testcase_22 AC 163 ms
53,344 KB
testcase_23 AC 431 ms
58,360 KB
testcase_24 AC 144 ms
51,592 KB
testcase_25 AC 201 ms
56,284 KB
testcase_26 AC 134 ms
53,340 KB
testcase_27 AC 48 ms
49,968 KB
testcase_28 AC 85 ms
52,748 KB
testcase_29 AC 52 ms
51,076 KB
testcase_30 AC 165 ms
54,360 KB
testcase_31 AC 165 ms
53,936 KB
testcase_32 AC 167 ms
54,396 KB
testcase_33 AC 164 ms
53,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        long t = sc.nextLong();
        ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            graph.get(a).add(b);
            graph.get(b).add(a);
        }
        long[][][] matrixes = new long[63][n][n];
        for (int i = 0; i < n; i++) {
            for (int x : graph.get(i)) {
                matrixes[0][i][x] = 1;
            }
        }
        for (int i = 1; i < 63; i++) {
            for (int a = 0; a < n; a++) {
                for (int b = 0; b < n; b++) {
                    for (int c = 0; c < n; c++) {
                        matrixes[i][a][c] += matrixes[i - 1][a][b] * matrixes[i - 1][b][c] % MOD;
                        matrixes[i][a][c] %= MOD;
                    }
                }
            }
        }
        long[] ans = new long[n];
        ans[0] = 1;
        for (int i = 62; i >= 0 && t > 0; i--) {
            if (t < (1L << i)) {
                continue;
            }
            long[] next = new long[n];
            t -= (1L << i);
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    next[j] += matrixes[i][j][k] * ans[k] % MOD;
                    next[j] %= MOD;
                }
            }
            ans = next;
        }
        System.out.println(ans[0]);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0