結果
| 問題 |
No.845 最長の切符
|
| コンテスト | |
| ユーザー |
lotus
|
| 提出日時 | 2019-06-28 22:48:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 828 bytes |
| コンパイル時間 | 1,668 ms |
| コンパイル使用メモリ | 174,280 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-07-02 05:02:57 |
| 合計ジャッジ時間 | 7,299 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 TLE * 1 -- * 14 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long i64;
typedef pair<i64,i64> P;
int n, m;
vector<P> v[20];
bool used[20];
i64 dfs(int now, i64 score){
i64 ret = score;
for(int i = 0; i < v[now].size(); i++){
if(used[v[now][i].first]) continue;
used[now] = 1;
ret = max(ret, dfs(v[now][i].first, score) + v[now][i].second);
used[v[now][i].first] = 0;
}
return ret;
}
int main(){
cin >> n >> m;
for(int i = 0; i < m; i++){
i64 a,b,c;
cin >> a >> b >> c;
v[a].push_back(P(b,c));
v[b].push_back(P(a,c));
}
for(int i = 0; i < n; i++){
sort(v[i].begin(), v[i].end(), greater<P>());
}
i64 ans = 0;
for(int i = 1; i <= n; i++){
used[i] = 1;
ans = max(ans, dfs(i, 0));
used[i] = 0;
}
cout << ans << endl;
return 0;
}
lotus