結果

問題 No.2733 Just K-times TSP
ユーザー otoshigootoshigo
提出日時 2024-04-19 22:37:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 1,567 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 203,032 KB
実行使用メモリ 48,912 KB
最終ジャッジ日時 2024-04-19 22:37:21
合計ジャッジ時間 3,881 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 16 ms
7,552 KB
testcase_18 AC 16 ms
7,552 KB
testcase_19 AC 19 ms
7,296 KB
testcase_20 AC 6 ms
6,940 KB
testcase_21 AC 15 ms
7,424 KB
testcase_22 AC 156 ms
48,912 KB
testcase_23 AC 16 ms
7,296 KB
testcase_24 AC 98 ms
25,728 KB
testcase_25 AC 98 ms
25,856 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 8 ms
5,376 KB
testcase_30 AC 19 ms
7,424 KB
testcase_31 AC 49 ms
13,312 KB
testcase_32 AC 115 ms
25,600 KB
testcase_33 AC 233 ms
48,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const int MOD=998244353;

int main(){
    ios::sync_with_stdio(false);
    std::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;
        u--;
        v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    int L=1;
    for(int i=0;i<N;i++)L*=K+1;
    vector dp(L,vector<ll>(N));
    for(int i=0;i<N;i++){
        int at=0;
        for(int j=0;j<N;j++){
            at=(K+1)*at+(i==j?1:0);
        }
        dp[at][i]=1;
    }
    for(int bit=0;bit<L;bit++){
        int b=bit;
        vector<int>v(N);
        for(int i=N-1;i>=0;i--){
            v[i]=b%(K+1);
            b/=K+1;
        }
        for(int i=0;i<N;i++){
            for(auto j:G[i]){
                if(v[j]<K){
                    int c=0;
                    for(int k=0;k<N;k++){
                        c=(K+1)*c+(k==j?v[k]+1:v[k]);
                    }
                    dp[c][j]+=dp[bit][i];
                    dp[c][j]%=MOD;
                }
            }
        }
    }
    ll ans=0;
    for(int i=0;i<N;i++){
        ans+=dp[L-1][i];
        ans%=MOD;
    }
    cout<<ans<<"\n";
}
0