#include<iostream>
#include<cstdio>
using namespace std;
int minn=9999999,book[101],n,e[101][101];
void dfs(int cur,int dis)
{
int j;
if(dis>minn) return ;
if(cur==n)
{
if(dis<minn) minn=dis;
return ;
}
for(j=1;j<=n;j++)
{
if(e[cur][j]!=9999999 && book[j]==0)
{
book[j]=1;
dfs(j,dis+e[cur][j]);
book[j]=0;
}
}
return;
}
int main()
{
int i,j,m,a,b,c;
cin>>n>>m;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(i==j) e[i][j]=0;
else e[i][j]=9999999;
}
}
for(i=1;i<=m;i++)
{
cin>>a>>b>>c;
e[a][b]=c;
}
book[1]=1;
dfs(1,0);
cout<<minn;
//system("pause");
return 0;
}
时间: 2024-10-30 15:12:07