結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー HIcoderHIcoder
提出日時 2023-07-15 19:59:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 1,380 bytes
コンパイル時間 1,133 ms
コンパイル使用メモリ 117,132 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 06:03:32
合計ジャッジ時間 7,162 ms
ジャッジサーバーID
(参考情報)
judge13 / 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 10 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 70 ms
4,348 KB
testcase_09 AC 70 ms
4,348 KB
testcase_10 AC 69 ms
4,348 KB
testcase_11 AC 53 ms
4,348 KB
testcase_12 AC 74 ms
4,348 KB
testcase_13 AC 70 ms
4,348 KB
testcase_14 AC 363 ms
4,348 KB
testcase_15 AC 372 ms
4,348 KB
testcase_16 AC 376 ms
4,348 KB
testcase_17 AC 378 ms
4,348 KB
testcase_18 AC 393 ms
4,348 KB
testcase_19 AC 374 ms
4,348 KB
testcase_20 AC 259 ms
4,348 KB
testcase_21 AC 299 ms
4,348 KB
testcase_22 AC 51 ms
4,348 KB
testcase_23 AC 355 ms
4,348 KB
testcase_24 AC 40 ms
4,348 KB
testcase_25 AC 97 ms
4,348 KB
testcase_26 AC 31 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 51 ms
4,348 KB
testcase_31 AC 48 ms
4,348 KB
testcase_32 AC 47 ms
4,348 KB
testcase_33 AC 46 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
#include<iostream>
#include<set> 
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include <unordered_set>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=998244353;


vector<vector<ll> > mat(vector<vector<ll> > A,vector<vector<ll> > B,int N){
    //A*B
    vector<vector<ll> > C(N,vector<ll>(N));
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            ll ans=0;
            for(int k=0;k<N;k++){
                ans = (ans + A[i][k]*B[k][j]%MOD)%MOD;
            }
            C[i][j] = ans;
        }
    }
    return C;

}


//行列xのy乗
vector<vector<ll> > multi_matrix(vector<vector<ll> >x, ll y ,int N){

    vector<vector<ll> > pow(N,vector<ll>(N));
    for(int i=0;i<N;i++) pow[i][i]=1;//単位行列
    
    while(y>0){
        if(y&1){
            pow = mat(pow,x,N);
        }
        y = y>>1;
        x = mat(x,x,N);
    }

    return pow;
} 

int main(){
    int N,M;
    ll T;
    cin>>N>>M>>T;
    
    vector<vector<ll>> matrix(N,vector<ll>(N,0));

    for(int i=0;i<M;i++){
        int s,t;
        cin>>s>>t;
        matrix[s][t]=1;
        matrix[t][s]=1;
    
    }

    auto res=multi_matrix(matrix,T,N);

    ll ans=0;
    
    ans+=res[0][0]*1;


    cout<<ans<<endl;
}
0