//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std; typedef long long ll;
inline int qr(){
register int ret=0,f=0;
register char c=getchar();
while(!isdigit(c))f|=c==45,c=getchar();
while(isdigit(c)) ret=ret*10+c-48,c=getchar();
return f?-ret:ret;
}
const int maxn=13;
const int inf=0x3f3f3f3f;
int e[maxn][maxn];
int dp[maxn][1<<maxn];
int dis[maxn][1<<maxn];
int n,m,rt;
int cnt=0;
int main(){
memset(e,0x3f,sizeof e);
memset(dp,0x3f,sizeof dp);
n=qr(); m=qr();
for(int t=1,t1,t2;t<=m;++t)
t1=qr(),t2=qr(),e[t1][t2]=e[t2][t1]=min(e[t1][t2],qr());
const int K=(1<<n)-1;
for(int t=0;t<=K;++t)
for(int g=1;g<=n;++g){
if(t<<1>>g&1) continue;
int f=inf;
for(int k=1;k<=n;++k)
if(t<<1>>k&1) f=min(f,e[g][k]);
dis[g][t]=f;
}
int ans=inf;
for(int rt=1;rt<=n;++rt){
memset(dp,0x3f,sizeof dp);
dp[1][1<<rt>>1]=0;
for(int t=2;t<=n;++t){
for(int i=1;i<=K;++i){
dp[t][i]=dp[t-1][i];
for(int l=i;l;--l&=i){
int c=l^i,ret=0;
if(dp[t-1][c]>=dp[t][i])continue;
bool f=0;
for(int g=1;g<=n;++g)
if(l<<1>>g&1){
if(dis[g][c]>=inf){ret=inf; break;}
else ret+=dis[g][c];
if(dp[t-1][c]+(t-1)*ret>=dp[t][i]) {f=1;break;}
}
if(f)continue;
dp[t][i]=min((ll)dp[t][i],dp[t-1][c]+(t-1ll)*ret);
}
}
ans=min(ans,dp[t][K]);
}
ans=min(ans,dp[1][K]);
}
printf("%d\n",ans);
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 77.69 us | 460 KB | Accepted | Score: 5 | 显示更多 |
Testcase #2 | 135.83 us | 476 KB | Accepted | Score: 5 | 显示更多 |
Testcase #3 | 631.22 us | 488 KB | Accepted | Score: 5 | 显示更多 |
Testcase #4 | 666.57 us | 488 KB | Accepted | Score: 5 | 显示更多 |
Testcase #5 | 1.153 ms | 488 KB | Accepted | Score: 5 | 显示更多 |
Testcase #6 | 372.71 us | 484 KB | Accepted | Score: 5 | 显示更多 |
Testcase #7 | 189.86 us | 480 KB | Accepted | Score: 5 | 显示更多 |
Testcase #8 | 378.16 us | 484 KB | Accepted | Score: 5 | 显示更多 |
Testcase #9 | 150.55 us | 476 KB | Accepted | Score: 5 | 显示更多 |
Testcase #10 | 214.81 us | 480 KB | Accepted | Score: 5 | 显示更多 |
Testcase #11 | 481.9 us | 484 KB | Accepted | Score: 5 | 显示更多 |
Testcase #12 | 455.09 us | 484 KB | Accepted | Score: 5 | 显示更多 |
Testcase #13 | 1.601 ms | 488 KB | Accepted | Score: 5 | 显示更多 |
Testcase #14 | 1.369 ms | 488 KB | Accepted | Score: 5 | 显示更多 |
Testcase #15 | 73.913 ms | 580 KB | Accepted | Score: 5 | 显示更多 |
Testcase #16 | 75.216 ms | 580 KB | Accepted | Score: 5 | 显示更多 |
Testcase #17 | 307.101 ms | 680 KB | Accepted | Score: 5 | 显示更多 |
Testcase #18 | 240.156 ms | 680 KB | Accepted | Score: 5 | 显示更多 |
Testcase #19 | 265.866 ms | 680 KB | Accepted | Score: 5 | 显示更多 |
Testcase #20 | 294.882 ms | 680 KB | Accepted | Score: 5 | 显示更多 |