結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー atjh16atjh16
提出日時 2021-12-27 10:02:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 1,025 bytes
コンパイル時間 2,241 ms
コンパイル使用メモリ 208,880 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 08:31:08
合計ジャッジ時間 5,642 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 5 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 28 ms
4,348 KB
testcase_09 AC 28 ms
4,348 KB
testcase_10 AC 27 ms
4,348 KB
testcase_11 AC 22 ms
4,348 KB
testcase_12 AC 31 ms
4,348 KB
testcase_13 AC 28 ms
4,348 KB
testcase_14 AC 138 ms
4,348 KB
testcase_15 AC 143 ms
4,348 KB
testcase_16 AC 146 ms
4,348 KB
testcase_17 AC 149 ms
4,348 KB
testcase_18 AC 154 ms
4,348 KB
testcase_19 AC 148 ms
4,348 KB
testcase_20 AC 103 ms
4,348 KB
testcase_21 AC 116 ms
4,348 KB
testcase_22 AC 21 ms
4,348 KB
testcase_23 AC 142 ms
4,348 KB
testcase_24 AC 17 ms
4,348 KB
testcase_25 AC 39 ms
4,348 KB
testcase_26 AC 14 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 21 ms
4,348 KB
testcase_31 AC 20 ms
4,348 KB
testcase_32 AC 20 ms
4,348 KB
testcase_33 AC 20 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long t, n, m, u, v;
const long long M = 998244353;
typedef vector<vector<long long>> mat;

mat mprod(mat& a, mat& b) {
    mat c(a.size(), vector<long long>(b[0].size()));

    for (int i = 0; i < a.size(); i++) {
        for (int k = 0; k < b.size(); k++) {
            for (int j = 0; j < b[0].size(); j++) {
                c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % M;
            }
        }
    }

    return c;
}

mat powmat(mat a, long long t) {
    mat b(a.size(), vector<long long>(a.size()));

    for (int i = 0; i < a.size(); i++)
        b[i][i] = 1;

    while (t > 0) {
        if (t & 1)
            b = mprod(b, a);

        a = mprod(a, a);
        t >>= 1;
    }

    return b;
}

int main(){
    cin >> n >> m >> t;
    
    mat a(n, vector<long long> (n, 0));
    
    for(int i = 0; i < m; i++){
        cin >> u >> v;
        
        a[u][v] = 1;
        a[v][u] = 1;
    }
    
    mat b = powmat(a, t);
            
    cout << b[0][0] << endl;
}
0