結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー ramdosramdos
提出日時 2021-10-17 19:58:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 429 ms / 2,000 ms
コード長 1,713 bytes
コンパイル時間 840 ms
コンパイル使用メモリ 82,672 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 06:24:36
合計ジャッジ時間 7,169 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 12 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 79 ms
4,380 KB
testcase_09 AC 80 ms
4,376 KB
testcase_10 AC 80 ms
4,380 KB
testcase_11 AC 62 ms
4,380 KB
testcase_12 AC 85 ms
4,376 KB
testcase_13 AC 80 ms
4,384 KB
testcase_14 AC 399 ms
4,376 KB
testcase_15 AC 408 ms
4,376 KB
testcase_16 AC 411 ms
4,380 KB
testcase_17 AC 417 ms
4,380 KB
testcase_18 AC 429 ms
4,380 KB
testcase_19 AC 413 ms
4,376 KB
testcase_20 AC 285 ms
4,376 KB
testcase_21 AC 332 ms
4,376 KB
testcase_22 AC 58 ms
4,380 KB
testcase_23 AC 389 ms
4,380 KB
testcase_24 AC 46 ms
4,376 KB
testcase_25 AC 108 ms
4,380 KB
testcase_26 AC 36 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 57 ms
4,376 KB
testcase_31 AC 53 ms
4,376 KB
testcase_32 AC 53 ms
4,376 KB
testcase_33 AC 51 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

const long long mod=998244353;

vector<vector<long long>> matrix_mul(const vector<vector<long long>>& A,const vector<vector<long long>>&B){
  vector<vector<long long>>C(A.size(),vector<long long>(B.at(0).size(),0));
  for(int i=0;i<A.size();i++){
    for(int k=0;k<B.size();k++){
      for(int j=0;j<B.at(0).size();j++){
        C.at(i).at(j)=(C.at(i).at(j)+A.at(i).at(k)*B.at(k).at(j))%mod;
      }
    }
  }
  return C;
}

vector<vector<long long>> matrix_exp(vector<vector<long long>> X,long long n){
  vector<vector<long long>>Y(X.size(),vector<long long>(X.size(),0));
  for(int i=0;i<X.size();i++){
    Y.at(i).at(i)=1;
  }
  while(n>0){
    if(n&1){
      Y=matrix_mul(Y,X);
    }
    X=matrix_mul(X,X);
    n>>=1;
  }
  return Y;
}

long long calculate_nth(long long n,vector<vector<long long>> A, vector<vector<long long>> b){
  A=matrix_exp(A,n);
  vector<vector<long long>> res;
  res=matrix_mul(A,b);
  return res.at(0).at(0);
}

long long mod_pow(long long x,long long n,long long m){
  long long res=1;
  while(n>0){
    if(n&1){
      res=res*x%m;
    }
    x=x*x%m;
    n>>=1;
  }
  return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    long long n, m, t;
    cin >> n >> m >> t;
    vector<vector<long long>> a(n, vector<long long>(n, 0));
    vector<vector<long long>> b(n, vector<long long>(n, 0));
    b[0][0] = 1;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        a[u][v] = 1;
        a[v][u] = 1;
    }
    long long ans;
    ans=calculate_nth(t,a,b);
    cout<<ans<<endl;
}
0