提交记录 7994
提交时间 |
评测时间 |
2019-01-26 21:46:55 |
2020-08-01 01:11:29 |
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=15,K=(1<<12)+5,INF=0x3f3f3f3f;
int n,m,u,v,ww,ans=INF;
int f[K],d[N],g[N][N];
inline void dfs(int now)
{
if(now==(1<<n)-1)
return;
for(int i=1;i<=n;i++)
{
if((now&(1<<i-1))==0)
continue;
for(int j=1;j<=n;j++)
{
if(g[i][j]==INF)
continue;
if(now&(1<<j-1))
continue;
d[j]=d[i]+1;
if(f[now|(1<<j-1)]>f[now]+g[i][j]*d[j])
{
f[now|(1<<j-1)]=f[now]+g[i][j]*d[j];
dfs(now|(1<<j-1));
}
d[j]=0;
}
}
}
int main()
{
memset(g,0x3f,sizeof(g));
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&u,&v,&ww);
g[u][v]=g[v][u]=min(g[u][v],ww);
}
for(int i=1;i<=n;i++)
{
memset(f,0x3f,sizeof(f));
f[1<<i-1]=0;
dfs(1<<i-1);
ans=min(ans,f[(1<<n)-1]);
}
printf("%d\n",ans);
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 10.2 us | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #2 | 17.34 us | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #3 | 26.19 us | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #4 | 41.45 us | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #5 | 170.31 us | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #6 | 137.61 us | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #7 | 45.14 us | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #8 | 120.61 us | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #9 | 70.9 us | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #10 | 79.39 us | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #11 | 198 us | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #12 | 189.22 us | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #13 | 706.92 us | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #14 | 768.7 us | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #15 | 27.773 ms | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #16 | 37.045 ms | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #17 | 68.879 ms | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #18 | 109.575 ms | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #19 | 139.302 ms | 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #20 | 113.513 ms | 32 KB | Accepted | Score: 5 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-11-25 18:56:07 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠