結果

問題 No.845 最長の切符
ユーザー ahe100ahe100
提出日時 2019-06-28 22:55:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,024 bytes
コンパイル時間 1,637 ms
コンパイル使用メモリ 167,772 KB
実行使用メモリ 134,624 KB
最終ジャッジ日時 2023-09-14 22:30:36
合計ジャッジ時間 8,840 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
134,624 KB
testcase_01 AC 41 ms
134,428 KB
testcase_02 AC 41 ms
134,420 KB
testcase_03 AC 41 ms
134,524 KB
testcase_04 AC 41 ms
134,464 KB
testcase_05 AC 41 ms
134,476 KB
testcase_06 AC 40 ms
134,432 KB
testcase_07 AC 38 ms
134,432 KB
testcase_08 AC 38 ms
134,472 KB
testcase_09 AC 38 ms
134,484 KB
testcase_10 AC 47 ms
134,424 KB
testcase_11 AC 39 ms
134,432 KB
testcase_12 AC 40 ms
134,424 KB
testcase_13 AC 39 ms
134,492 KB
testcase_14 AC 39 ms
134,436 KB
testcase_15 AC 319 ms
134,488 KB
testcase_16 TLE -
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 rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
グラフ上の最長経路問題
*/

ll n,m,dp[1<<16][16][16],ans=-1e18;
vector<ll> v[20],d[20];

ll f(ll s,ll p,ll q){
	if(dp[s][p][q]!=-1e18)return dp[s][p][q];
	ll sum=0;
	rep(i,v[p].size()){
		if(!(1 & s>>v[p][i])){
			sum=max(sum,f(s+(1<<v[p][i]),v[p][i],q)+d[p][i]);
		}
	}
	rep(i,v[q].size()){
		if(!(1 & s>>v[q][i])){
			sum=max(sum,f(s+(1<<v[q][i]),p,v[q][i])+d[q][i]);
		}
	}
	return dp[s][p][q]=sum;
}

void init(){
	cin>>n>>m;
	rep(i,m){
		ll a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		v[a].push_back(b);
		v[b].push_back(a);
		d[a].push_back(c);
		d[b].push_back(c);
	}
	rep(i,1<<16)rep(j,16)rep(k,16)dp[i][j][k]=-1e18;
}

int main(void){
	init();
	rep(i,n){
		ans=max(ans,f(1<<i,i,i));
	}
	cout<<ans<<endl;
	return 0;
}
0