結果
| 問題 |
No.845 最長の切符
|
| コンテスト | |
| ユーザー |
ttttan2
|
| 提出日時 | 2019-06-28 23:03:56 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 332 ms / 3,000 ms |
| コード長 | 1,509 bytes |
| コンパイル時間 | 1,453 ms |
| コンパイル使用メモリ | 164,688 KB |
| 実行使用メモリ | 12,288 KB |
| 最終ジャッジ日時 | 2024-07-02 05:07:46 |
| 合計ジャッジ時間 | 4,120 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
if(a<b)return b;
else return a;
}
ll lmin(ll a,ll b){
if(a<b)return a;
else return b;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll n,m;cin>>n>>m;
ll d[n+1][n+1];
rep(i,0,n+1){
rep(j,0,n+1)d[i][j]=-1;
}
rep(i,0,m){
ll a,b,c;cin>>a>>b>>c;
d[a][b]=max(d[a][b],c);
d[b][a]=d[a][b];
}
vector<ll> v[n+1];
rep(i,1,n+1){
rep(j,1,n+1){
if(d[i][j]!=-1)v[i].push_back(j);
}
}
ll u=pow(2,n);
ll dp[u][n+1];
rep(i,0,u)rep(j,0,n+1)dp[i][j]=-1;
int now=1;
rep(i,0,n){
dp[now][i+1]=0;
now*=2;
}
rep(i,1,u){
rep(k,1,n+1){
if(dp[i][k]==-1)continue;
rep(j,0,n){
int r=pow(2,j);
int t=i/r;
if(t%2==1)continue;
if(d[k][j+1]==-1)continue;
dp[i+r][j+1]=max(dp[i+r][j+1],dp[i][k]+d[k][j+1]);
}
}
}
ll ans=0;
rep(i,0,u)rep(j,1,n+1)ans=max(ans,dp[i][j]);
cout<<ans<<endl;
}
ttttan2