提交记录 8328
提交时间 |
评测时间 |
2019-02-12 19:12:09 |
2020-08-01 01:16:48 |
#include<iostream>
#include<cstdio>
using namespace std;
int dis[13],n,m,G[13][13],limit,f[8192],inf=1e9+7,ans=1e9;
void dfs(int x)
{
for(int i=1;i<=n;i++)
if((1<<(i-1))&x)
for(int j=1;j<=n;j++)
if(((1<<(j-1))&x)==0&&G[i][j]!=inf)
if(dis[i]*G[i][j]+f[x]<f[(x|(1<<(j-1)))])
{
f[x|(1<<(j-1))]=dis[i]*G[i][j]+f[x];
int t=dis[j];
dis[j]=dis[i]+1;
dfs(x|(1<<(j-1)));
dis[j]=t;
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
G[i][j]=inf;
limit=(1<<n);
for(int i=1;i<=m;i++)
{
int u,v,w;
cin>>u>>v>>w;
G[v][u]=G[u][v]=min(G[u][v],min(G[v][u],w));
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
dis[j]=inf;
for(int j=0;j<limit;j++)
f[j]=inf;
f[(1<<(i-1))]=0;
dis[i]=1;
dfs(1<<(i-1));
ans=min(ans,f[limit-1]);
}
cout<<ans;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 37.54 us | 40 KB | Accepted | Score: 5 | 显示更多 |
Testcase #2 | 47.23 us | 40 KB | Accepted | Score: 5 | 显示更多 |
Testcase #3 | 50.78 us | 40 KB | Accepted | Score: 5 | 显示更多 |
Testcase #4 | 72.36 us | 40 KB | Accepted | Score: 5 | 显示更多 |
Testcase #5 | 227.88 us | 40 KB | Accepted | Score: 5 | 显示更多 |
Testcase #6 | 160.1 us | 40 KB | Accepted | Score: 5 | 显示更多 |
Testcase #7 | 72.23 us | 40 KB | Accepted | Score: 5 | 显示更多 |
Testcase #8 | 146.9 us | 40 KB | Accepted | Score: 5 | 显示更多 |
Testcase #9 | 249.83 us | 40 KB | Accepted | Score: 5 | 显示更多 |
Testcase #10 | 170.56 us | 40 KB | Accepted | Score: 5 | 显示更多 |
Testcase #11 | 237.51 us | 40 KB | Accepted | Score: 5 | 显示更多 |
Testcase #12 | 234.36 us | 40 KB | Accepted | Score: 5 | 显示更多 |
Testcase #13 | 627.68 us | 40 KB | Accepted | Score: 5 | 显示更多 |
Testcase #14 | 714.57 us | 40 KB | Accepted | Score: 5 | 显示更多 |
Testcase #15 | 18.83 ms | 48 KB | Accepted | Score: 5 | 显示更多 |
Testcase #16 | 25.384 ms | 48 KB | Accepted | Score: 5 | 显示更多 |
Testcase #17 | 51.486 ms | 56 KB | Accepted | Score: 5 | 显示更多 |
Testcase #18 | 72.06 ms | 56 KB | Accepted | Score: 5 | 显示更多 |
Testcase #19 | 90.995 ms | 56 KB | Accepted | Score: 5 | 显示更多 |
Testcase #20 | 74.01 ms | 56 KB | Accepted | Score: 5 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-11-25 18:24:22 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠