結果

問題 No.2733 Just K-times TSP
ユーザー kaichou243kaichou243
提出日時 2024-04-19 21:52:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 804 ms / 2,000 ms
コード長 1,315 bytes
コンパイル時間 2,139 ms
コンパイル使用メモリ 207,388 KB
実行使用メモリ 32,256 KB
最終ジャッジ日時 2024-04-19 21:52:20
合計ジャッジ時間 5,941 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 44 ms
6,016 KB
testcase_18 AC 54 ms
6,016 KB
testcase_19 AC 65 ms
5,888 KB
testcase_20 AC 11 ms
5,376 KB
testcase_21 AC 33 ms
5,760 KB
testcase_22 AC 423 ms
32,240 KB
testcase_23 AC 48 ms
5,760 KB
testcase_24 AC 336 ms
17,536 KB
testcase_25 AC 316 ms
17,536 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 8 ms
5,376 KB
testcase_29 AC 24 ms
5,376 KB
testcase_30 AC 72 ms
5,760 KB
testcase_31 AC 184 ms
9,600 KB
testcase_32 AC 445 ms
17,408 KB
testcase_33 AC 804 ms
32,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
void mpl(ll& x,ll y){
	x+=y;
	if(x>998244353) x-=998244353;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,m,k;
	cin>>n>>m>>k;
	vector<vector<int>> g(n);
	for(int i=0;i<m;i++){
	    int u,v;
	    cin>>u>>v;
	    g[--u].push_back(--v);
	    g[v].push_back(u);
	}
	int cnts=1;
	for(int i=0;i<n;i++) cnts*=(k+1);
	vector<vector<ll>> dp(n,vector<ll>(cnts));
	auto turn_vec=[&](int state)->vector<int>{
	    vector<int> ret;
	    for(int i=0;i<n;i++){
	        ret.push_back(state%(k+1));
	        state/=k+1;
	    }
	    return ret;
	};
	auto turn_int=[&](vector<int> state)->int{
	    int ret=0,pw=1;
	    for(int i=0;i<n;i++){
	        ret+=pw*state[i];
	        pw*=k+1;
	    }
	    return ret;
	};
	for(int i=0;i<n;i++){
	    vector<int> state(n);
	    state[i]=1;
	    dp[i][turn_int(state)]=1;
	}
	for(int s=1;s<cnts;s++){
	    vector<int> state=turn_vec(s);
	    for(int i=0;i<n;i++){
	        for(auto& nv:g[i]){
	            if(state[nv]<k){
	                vector<int> new_state=state;
	                new_state[nv]++;
	                int ns=turn_int(new_state);
	                mpl(dp[nv][ns],dp[i][s]);
	            }
	        }
	    }
	}
	ll ans=0;
	for(int i=0;i<n;i++) mpl(ans,dp[i][cnts-1]);
	cout<<ans<<endl;
}
0