結果

問題 No.845 最長の切符
ユーザー TlapesiumTlapesium
提出日時 2019-02-16 21:30:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 821 bytes
コンパイル時間 1,746 ms
コンパイル使用メモリ 175,232 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2023-10-25 06:14:59
合計ジャッジ時間 6,971 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
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>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

vector<vector<int> > mat;
int N, M;

int dfs(int pos, int dist, vector<bool> used) {
	int tmp = dist;
	for (int i = 0; i < N; i++) {
		if (mat[pos][i] != -1 && !used[i]) {
			used[i] = true;
			tmp = max(tmp, dfs(i, dist + mat[pos][i], used));
			used[i] = false;
		}
	}
	return tmp;
}
int main() {
	cin >> N >> M;
	mat = vector<vector<int> >(N, vector<int>(N, -1));
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		mat[a][b] = mat[b][a] = c;
	}
	int ans = -1;
	for (int i = 0; i < N; i++) {
		vector<bool> tmp(N, false);
		tmp[i] = true;
		ans = max(ans,dfs(i, 0, tmp));
	}
	cout << ans << endl;
}
0