結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー kokatsukokatsu
提出日時 2021-11-20 00:40:25
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,020 ms / 2,000 ms
コード長 1,108 bytes
コンパイル時間 1,926 ms
コンパイル使用メモリ 200,152 KB
実行使用メモリ 8,552 KB
最終ジャッジ日時 2023-09-04 15:04:18
合計ジャッジ時間 13,590 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 24 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 177 ms
4,416 KB
testcase_09 AC 177 ms
4,380 KB
testcase_10 AC 177 ms
4,408 KB
testcase_11 AC 134 ms
4,380 KB
testcase_12 AC 189 ms
4,380 KB
testcase_13 AC 178 ms
4,376 KB
testcase_14 AC 947 ms
8,488 KB
testcase_15 AC 969 ms
8,516 KB
testcase_16 AC 978 ms
8,544 KB
testcase_17 AC 990 ms
8,512 KB
testcase_18 AC 1,020 ms
8,504 KB
testcase_19 AC 974 ms
8,552 KB
testcase_20 AC 673 ms
6,648 KB
testcase_21 AC 781 ms
5,508 KB
testcase_22 AC 135 ms
4,380 KB
testcase_23 AC 921 ms
8,476 KB
testcase_24 AC 106 ms
4,388 KB
testcase_25 AC 253 ms
4,380 KB
testcase_26 AC 82 ms
4,380 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 7 ms
4,376 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 133 ms
4,384 KB
testcase_31 AC 125 ms
4,412 KB
testcase_32 AC 122 ms
4,392 KB
testcase_33 AC 119 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    long N, M, T;
    readf("%d %d %d\n", N, M, T);

    auto path = new long[][](N, N);
    foreach (i; 0 .. M) {
        long s, t;
        readf("%d %d\n", s, t);

        path[s][t] = 1;
        path[t][s] = 1;
    }

    enum long MOD = 998244353;

    auto mat = matPowMod(path, T, MOD);

    long res = mat[0][0];
    res.writeln;
}

long[][] matMulMod(long[][] a, long[][] b, long m) {
    long l = a[0].length.to!long;

    assert(l == b.length);

    auto res = new long[][](a.length, b[0].length);
    foreach (i, r; res) {
        foreach (k; 0 .. l) {
            foreach (j, ref e; r) {
                e = (e + a[i][k] * b[k][j]) % m;
            }
        }
    }

    return res;
}

long[][] matPowMod(long[][] mat, long p, long m) {
    long l = mat[0].length.to!long;

    assert(l == mat.length);

    auto res = new long[][](l, l);
    foreach (i; 0 .. l) {
        res[i][i] = 1;
    }

    while (p > 0) {
        if (p & 1) {
            res = matMulMod(res, mat, m);
        }
        mat = matMulMod(mat, mat, m);
        p >>= 1;
    }

    return res;
}
0