結果

問題 No.845 最長の切符
ユーザー lotuslotus
提出日時 2019-06-28 22:48:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 828 bytes
コンパイル時間 1,774 ms
コンパイル使用メモリ 172,796 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-14 22:28:26
合計ジャッジ時間 7,612 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
7,536 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 918 ms
4,376 KB
testcase_11 AC 169 ms
4,380 KB
testcase_12 AC 19 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0