結果
問題 | No.2733 Just K-times TSP |
ユーザー | GGanari |
提出日時 | 2024-04-19 23:15:38 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,056 ms / 2,000 ms |
コード長 | 1,228 bytes |
コンパイル時間 | 2,476 ms |
コンパイル使用メモリ | 204,136 KB |
実行使用メモリ | 265,600 KB |
最終ジャッジ日時 | 2024-10-11 17:44:20 |
合計ジャッジ時間 | 12,286 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> #define INF 1000000001LL #define LNF 1000000000000000001LL #define MOD 998244353LL #define MAX 1005 #define long long long #define all(x) x.begin(),x.end() using namespace std; int mp[1<<26]; vector<int> graph[10]; int convert(vector<int> arr) { int res = 0; int cur = 1; for(int i = 0; i<arr.size(); i++) { res+=cur*arr[i]; cur*=9; } return res; } long dfs(int x,vector<int> cur, int sum) { if(sum == 0) return 1; int p = convert(cur); if(mp[p] != -1) return mp[p]; mp[p] = 0; auto &t = mp[p]; for(int y : graph[x]) { if(cur[y] == 0) continue; cur[0] = y; cur[y]--; t= (t+dfs(y,cur,sum-1))%MOD; cur[y]++; } return t; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); memset(mp,-1,sizeof mp); int n,m,k; cin >> n >> m >> k; for(int i = 0; i<m; i++) { int a,b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } vector<int> vis(n+1,k); vis[0] = 0; for(int i = 1; i<=n; i++) graph[0].push_back(i); cout << dfs(0,vis,k*n) << endl; return 0; }