結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー inksamuraiinksamurai
提出日時 2021-11-19 21:45:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 265 ms / 2,000 ms
コード長 2,636 bytes
コンパイル時間 2,042 ms
コンパイル使用メモリ 179,908 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 07:57:18
合計ジャッジ時間 7,178 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 8 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 50 ms
4,380 KB
testcase_09 AC 50 ms
4,380 KB
testcase_10 AC 50 ms
4,380 KB
testcase_11 AC 39 ms
4,380 KB
testcase_12 AC 53 ms
4,380 KB
testcase_13 AC 50 ms
4,380 KB
testcase_14 AC 247 ms
4,380 KB
testcase_15 AC 251 ms
4,376 KB
testcase_16 AC 254 ms
4,376 KB
testcase_17 AC 258 ms
4,380 KB
testcase_18 AC 265 ms
4,380 KB
testcase_19 AC 254 ms
4,380 KB
testcase_20 AC 175 ms
4,380 KB
testcase_21 AC 197 ms
4,380 KB
testcase_22 AC 35 ms
4,376 KB
testcase_23 AC 240 ms
4,380 KB
testcase_24 AC 28 ms
4,380 KB
testcase_25 AC 66 ms
4,376 KB
testcase_26 AC 22 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 34 ms
4,380 KB
testcase_31 AC 33 ms
4,376 KB
testcase_32 AC 31 ms
4,380 KB
testcase_33 AC 31 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3HaBFkZ ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vector<int>;

//snuke's modular int
template <ll mod>
struct modularint{
	ll x;
	modularint(ll x=0):x(x%mod){}
	modularint& operator+=(const modularint a){
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	modularint& operator-=(const modularint a){
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	modularint& operator*=(const modularint a){
		(x *= a.x) %= mod;
		return *this;
	}
	modularint operator+(const modularint a)const{
		modularint res(*this);
		return res+=a;
	}
	modularint operator-(const modularint a)const{
		modularint res(*this);
		return res-=a;
	}
	modularint operator*(const modularint a)const{
		modularint res(*this);
		return res*=a;
	}
	modularint pow(ll n)const{
		modularint res=1,x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	modularint inv()const{
		return pow(mod-2);
	}
};
using mint=modularint<998244353>;

template <typename T>
struct matrix{
	vec(vec(T)) a;
	//initilize matrix here
	matrix(){}
	matrix(int h,int w){
		a.clear();
		a.resize(h,vec(T)(w));
	}
	matrix(vec(vec(T)) nea){
		a=nea;
	}
	//outer vector size here
	int size()const{ return a.size(); }
	const vector<T>& operator[](int i)const{ return a[i]; }
	vector<T>& operator[](int i){ return a[i]; }
	matrix<T>& operator *=(const matrix<T>& rhs){
		int h=a.size(), w=rhs[0].size(), c=rhs.size();
		matrix<T> res(h,w);
		rep(i,h){
			rep(j,w){
				rep(k,c){
					res[i][j] += a[i][k] * rhs[k][j];
				}
			}	
		}
		this->a = res.a;
		return *this;
	}
	matrix<T> operator *(const matrix<T>& rhs){
		return (matrix<T>(*this) *= rhs);
	}
};
template <typename T>
matrix<T> idenmat(int n){
	matrix<T> res(n,n);
	rep(i,n) res.a[i][i] = 1;
	return res;
};
template <typename T>
matrix<T> pow(matrix<T> mat,ll n){
	matrix<T> res=idenmat<T>(mat.size());
	while(n){
		if(n&1) res*=mat;
		mat*=mat;
		n>>=1;
	}
	return res;
};

int main(){
_3HaBFkZ;
	ll n,m,t;
	cin>>n>>m>>t;
	vec(vec(mint)) wys(n,vec(mint)(n,0));
	rep(i,m){
		int u,v;
		cin>>u>>v;
		wys[u][v]=wys[u][v]+1;
		wys[v][u]=wys[v][u]+1;
	}
	matrix<mint> mat(wys);
	matrix<mint> now=idenmat<mint>(n);
	now=now*pow(mat,t);
	cout<<now[0][0].x<<"\n";
//	
	return 0;
}
0