結果
| 問題 |
No.845 最長の切符
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2019-07-03 23:30:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,115 bytes |
| コンパイル時間 | 1,567 ms |
| コンパイル使用メモリ | 167,220 KB |
| 実行使用メモリ | 14,292 KB |
| 最終ジャッジ日時 | 2024-09-17 06:22:21 |
| 合計ジャッジ時間 | 9,211 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 TLE * 1 -- * 14 |
ソースコード
#include <bits/stdc++.h>
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))
using ll = std::int64_t;
using P = std::tuple<int,int>;
int N, M;
int di[16][16], dp[1<<16][16];
int rec(int visited, int v){
if(dp[visited][v] != -1){
return dp[visited][v];
}
int mx = 0;
for(int w=0;w<N;++w){
if(di[v][w] == -1 || (visited >> w & 1)){
continue;
}
mx = std::max(mx, rec(visited | (1 << w), w) + di[v][w]);
}
return mx;
}
int main(){
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
std::cin >> N >> M;
std::fill(&di[0][0], &di[0][0] + 16 * 16, -1'000'000'000);
for(int i=0;i<M;++i){
int a, b, c;
std::cin >> a >> b >> c;
a -= 1;
b -= 1;
di[a][b] = std::max(di[a][b], c);
di[b][a] = di[a][b];
}
memset(dp, -1, sizeof(dp));
int mx = 0;
for(int i=0;i<N;++i){
mx = std::max(mx, rec(1 << i, i));
}
std::cout << mx << std::endl;
}
tottoripaper