結果

問題 No.2832 Nana's Fickle Adventure
ユーザー 沙耶花沙耶花
提出日時 2024-08-02 23:00:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,433 bytes
コンパイル時間 4,589 ms
コンパイル使用メモリ 277,076 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-02 23:00:10
合計ジャッジ時間 9,381 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 47 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 83 ms
6,944 KB
testcase_04 AC 46 ms
6,940 KB
testcase_05 AC 8 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 13 ms
6,944 KB
testcase_09 AC 8 ms
6,940 KB
testcase_10 AC 13 ms
6,944 KB
testcase_11 AC 84 ms
6,940 KB
testcase_12 AC 83 ms
6,944 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 153 ms
6,940 KB
testcase_19 AC 181 ms
6,944 KB
testcase_20 AC 155 ms
6,940 KB
testcase_21 AC 163 ms
6,944 KB
testcase_22 AC 147 ms
6,940 KB
testcase_23 AC 159 ms
6,940 KB
testcase_24 AC 167 ms
6,940 KB
testcase_25 AC 155 ms
6,940 KB
testcase_26 AC 209 ms
6,940 KB
testcase_27 AC 6 ms
6,944 KB
testcase_28 AC 12 ms
6,944 KB
testcase_29 AC 93 ms
6,940 KB
testcase_30 AC 130 ms
6,944 KB
testcase_31 AC 156 ms
6,944 KB
testcase_32 AC 51 ms
6,944 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 3 ms
6,944 KB
testcase_35 AC 13 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 163 ms
6,940 KB
testcase_38 AC 3 ms
6,940 KB
testcase_39 AC 87 ms
6,944 KB
testcase_40 AC 47 ms
6,940 KB
testcase_41 AC 89 ms
6,940 KB
testcase_42 AC 95 ms
6,940 KB
testcase_43 AC 163 ms
6,944 KB
testcase_44 AC 6 ms
6,944 KB
testcase_45 AC 3 ms
6,940 KB
testcase_46 AC 5 ms
6,944 KB
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

template <class S,
          S (*op0)(S, S),
          S (*e0)(),
		  S (*op1)(S, S),
          S (*e1)()
          >
struct matrix{
	vector<vector<S>> v;
	int _h,_w;
	
	matrix(vector<vector<S>> X){
		v = X;
		_h = X.size();
		_w = 0;
		if(X.size()>0)_w = X[0].size();
	}
	
	matrix(int h,int w){
		v.resize(h,vector<S>(w,e0()));
		_h = h;
		_w = w;
	}
	
	void add_element(int from,int to,S x){
		v[to][from] = op0(v[to][from],x);
	}
	
	matrix e(){
		assert(_h==_w);
		matrix<S,op0,e0,op1,e1> ret(_h,_w);
		for(int i=0;i<_h;i++){
			for(int j=0;j<_w;j++){
				if(i==j)ret.v[i][j] = e1();
				else ret.v[i][j] = e0();
			}
		}
		return ret;
	}
	
	matrix &operator*=(const matrix &another){
		matrix<S,op0,e0,op1,e1> ret(_h,another._w);
		for(int i=0;i<_h;i++){
			for(int j=0;j<another._w;j++){
				ret.v[i][j] = e0();
				for(int k=0;k<_w;k++){
					ret.v[i][j] = op0(ret.v[i][j],op1(v[i][k],another.v[k][j]));
				}
			}
		}

		v = ret.v;
		return (*this);
	}
	
	matrix operator*(const matrix &another)const{
		return (matrix(*this)*=another);
	}
	
	matrix pow(long long cnt){
		matrix<S,op0,e0,op1,e1> ret = e();
		auto temp = *this;
		while(cnt!=0LL){
			if((cnt&1)==1){
				ret *= temp;
			}
			temp *= temp;
			cnt>>=1;
		}
		return ret;
	}
};

mint op0(mint a,mint b){
	return a+b;
}

mint e0(){
	return 0;
}

mint op1(mint a,mint b){
	return a*b;
}

mint e1(){
	return 1;
}
int main(){
	int n,m,x;
	cin>>n>>m>>x;
	vector e(n,vector<int>(n,0));
	vector<int> s(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--,b--;
		e[a][b]++;
		if(a!=b)e[b][a]++;
		s[a]++;
		if(a!=b)s[b]++;
	}
	int X = (n+1)*(n+1);
	matrix<mint,op0,e0,op1,e1> A(X,X);
	rep(i,n){
		rep(j,n){
			rep(k,n){
				int rem = e[j][k];
				if(i==k)rem--;
				if(rem>0&&s[j]>=2)A.add_element(i*(n+1)+j, j*(n+1)+k, mint(rem)/mint(s[j]-1));
				
			}
			if(s[i]!=0)A.add_element(n*(n+1)+i, i*(n+1)+j, mint(e[i][j])/mint(s[i]));
			if(s[j]==1 && e[j][i]==1){
				A.add_element(i*(n+1)+j, n*(n+1)+j, 1);
				
			}
		}
		
	}
	A = A.pow(x);
	matrix<mint,op0,e0,op1,e1> B(X,1);
	B.v[n*(n+1)][0] = 1;
	B = A * B;
	rep(i,n){
		mint sum = 0;
		rep(j,n+1){
			sum += B.v[j*(n+1)+i][0];
		}
		cout<<sum.val()<<endl;
	}
    return 0;
}
0