結果

問題 No.2733 Just K-times TSP
ユーザー shkiiii_shkiiii_
提出日時 2024-04-19 23:36:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,005 bytes
コンパイル時間 3,932 ms
コンパイル使用メモリ 386,560 KB
実行使用メモリ 149,412 KB
最終ジャッジ日時 2024-04-19 23:37:08
合計ジャッジ時間 17,551 ms
ジャッジサーバーID
(参考情報)
judge1 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,764 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 4 ms
6,940 KB
testcase_15 AC 22 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 113 ms
14,208 KB
testcase_18 AC 210 ms
20,864 KB
testcase_19 AC 459 ms
30,976 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 25 ms
6,944 KB
testcase_22 AC 1,398 ms
111,488 KB
testcase_23 AC 119 ms
12,800 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 5 ms
6,944 KB
testcase_28 AC 30 ms
6,944 KB
testcase_29 AC 137 ms
11,520 KB
testcase_30 AC 474 ms
28,544 KB
testcase_31 AC 1,413 ms
68,864 KB
testcase_32 TLE -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

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 main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n,m,K;
  cin >> n >> m >> K;
  map<vector<short>,ll> mp;
  vvi v(n);
  rep(i,m){
    int a,b;cin >> a >> b;
    a--;b--;
    v[a].emplace_back(b);
    v[b].emplace_back(a);
  }
  auto dfs = [&](auto &dfs,vector<short> &msk,int ov)->ll{
    if(mp.count(msk))return mp[msk];
    bool is = true;
    rep(i,n)if(msk[i] != K)is = false;
    if(is)return mp[msk] = 1;
    ll res = 0;
    for(auto nv : v[ov]){
      if(msk[nv] == K)continue;
      msk[nv]++;
      msk[n] = nv;
      (res += dfs(dfs,msk,nv))%= MOD;
      msk[nv]--;
    }
    msk[n] = ov;
    return mp[msk] = res;
  };
  ll res = 0;
  vector<short> msk(n+1);
  rep(i,n){
    msk[i] = 1;
    msk[n] = i;
    (res += dfs(dfs,msk,i))%= MOD;
    msk[i] = 0;
  }
  cout << res << "\n";

  

  return 0;
}
0