結果

問題 No.2733 Just K-times TSP
ユーザー shkiiii_shkiiii_
提出日時 2024-04-19 23:52:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 544 ms / 2,000 ms
コード長 1,998 bytes
コンパイル時間 7,744 ms
コンパイル使用メモリ 383,180 KB
実行使用メモリ 65,640 KB
最終ジャッジ日時 2024-04-19 23:52:56
合計ジャッジ時間 11,330 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
65,476 KB
testcase_01 AC 60 ms
65,560 KB
testcase_02 AC 61 ms
65,404 KB
testcase_03 AC 63 ms
65,536 KB
testcase_04 AC 61 ms
65,588 KB
testcase_05 AC 61 ms
65,552 KB
testcase_06 AC 61 ms
65,508 KB
testcase_07 AC 60 ms
65,520 KB
testcase_08 AC 61 ms
65,640 KB
testcase_09 AC 60 ms
65,488 KB
testcase_10 AC 69 ms
65,632 KB
testcase_11 AC 60 ms
65,344 KB
testcase_12 AC 60 ms
65,340 KB
testcase_13 AC 61 ms
65,528 KB
testcase_14 AC 59 ms
65,500 KB
testcase_15 AC 61 ms
65,564 KB
testcase_16 AC 60 ms
65,572 KB
testcase_17 AC 73 ms
65,408 KB
testcase_18 AC 79 ms
65,408 KB
testcase_19 AC 91 ms
65,464 KB
testcase_20 AC 60 ms
65,496 KB
testcase_21 AC 64 ms
65,456 KB
testcase_22 AC 209 ms
65,512 KB
testcase_23 AC 79 ms
65,472 KB
testcase_24 AC 223 ms
65,452 KB
testcase_25 AC 211 ms
65,344 KB
testcase_26 AC 59 ms
65,420 KB
testcase_27 AC 61 ms
65,404 KB
testcase_28 AC 62 ms
65,400 KB
testcase_29 AC 71 ms
65,404 KB
testcase_30 AC 95 ms
65,540 KB
testcase_31 AC 151 ms
65,508 KB
testcase_32 AC 307 ms
65,464 KB
testcase_33 AC 544 ms
65,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>
#include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}

int n,m,K;
vvi memo(531451,vi(10,-1));
vvi v(10);
vi Kp1(10,1);
inline ll dfs(ll msk,int ov){
    if(memo[msk][ov] != -1)return memo[msk][ov];
    ll MSK = msk;
    ll ok = 0;
    rep(i,n){
      if(MSK%(K+1) != K)ok += (1 << i);
      MSK /= (K+1);
    }
    if(!ok)return memo[msk][ov] = 1;
    ll res = 0;
    for(auto nv : v[ov]){
      if(!(ok >> nv & 1))continue;
      msk += Kp1[nv];
      (res += dfs(msk,nv))%= MOD;
      msk -= Kp1[nv];
    }
    return memo[msk][ov] = res;
  };

int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m >> K;
  rep(i,9)Kp1[i+1] = Kp1[i]*(K+1);
  rep(i,m){
    int a,b;cin >> a >> b;
    a--;b--;
    v[a].emplace_back(b);
    v[b].emplace_back(a);
  }
  ll res = 0;
  rep(i,n){
    (res += dfs(Kp1[i],i))%= MOD;
  }
  cout << res << "\n";

  

  return 0;
}
0