結果

問題 No.845 最長の切符
ユーザー kotamanegikotamanegi
提出日時 2019-06-28 21:54:29
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 1,576 ms / 3,000 ms
コード長 2,179 bytes
コンパイル時間 1,410 ms
コンパイル使用メモリ 115,704 KB
実行使用メモリ 35,968 KB
最終ジャッジ日時 2023-08-20 12:31:39
合計ジャッジ時間 8,182 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,384 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 10 ms
4,380 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 164 ms
8,056 KB
testcase_16 AC 586 ms
22,348 KB
testcase_17 AC 90 ms
8,992 KB
testcase_18 AC 456 ms
19,400 KB
testcase_19 AC 39 ms
5,576 KB
testcase_20 AC 1,576 ms
35,968 KB
testcase_21 AC 1,008 ms
23,012 KB
testcase_22 AC 89 ms
7,688 KB
testcase_23 AC 17 ms
4,480 KB
testcase_24 AC 646 ms
23,632 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 4 ms
4,384 KB
testcase_29 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
long long dp[17][(1 << 17)] = {};
long long path[17][17];
int main(){
#define int long long
	priority_queue<tuple<long long, long long, long long>, vector<tuple<long long, long long, long long>>, greater<tuple<long long, long long, long long>>> next;
	int n, m;
	cin >> n >> m;
	REP(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		path[a][b] = max(c, path[a][b]);
		path[b][a] = path[a][b];
	}
	REP(i, n) {
		next.push(make_tuple(0, i, (1 << i)));
	}
	while (next.empty() == false) {
		tuple<long long, long long, long long> now = next.top();
		next.pop();
		if (dp[get<1>(now)][get<2>(now)] == get<0>(now)) {
			//Marked as verifyed
			int now_here = get<1>(now);
			int donot_go = get<2>(now);
			int now_max = get<0>(now);
			for (int j = 0; j < n; ++j) {
				if (path[now_here][j] != 0) {
					//at least path exists
					if (((1 << j) & donot_go) == 0) {
						//ok to visit
						int next_max = now_max + path[now_here][j];
						int next_donotgo = donot_go + (1 << j);
						if (next_max > dp[j][next_donotgo]) {
							dp[j][next_donotgo] = next_max;
							next.push(make_tuple(next_max, j, next_donotgo));
						}
					}
				}
			}
		}
	}
	long long ans = 0;
	REP(i, 17) {
		REP(q, (1 << 17)) {
			ans = max(ans, dp[i][q]);
		}
	}
	cout << ans << endl;
}
0