样例没过,一分没有,有注释,感觉自己思路没错啊QwQ,(注:没有超时风险)。
#include<bits/stdc++.h>
using namespace std;
int n,u,v,w,minn=1e9,now,vis[1010];
struct node{//分别是从这个点连接的点,点之间的权值
int where,qu;
};
vector<node> t[1010];
void dfs(int x){
int size=t[x].size();//获得t[x]的大小
for(int i=0;i<size;i++){//查看里面所有点
if(vis[t[x][i].where]!=1){//如果没来过,因为题目说不走重复的边
vis[t[x][i].where]=1;//标记来过
now+=t[x][t[x][i].where].qu;//加上权值
if(now<minn)//判断如果比minn(答案) 小
minn=now;
dfs(t[x][i].where);//继续搜
now-=t[x][t[x][i].where].qu;//回溯,因为可能有其他到这个点的路径
vis[t[x][i].where]=0;
}
}
return;
}
int main(){
cin>>n;
while(cin>>u>>v>>w){
node nod;
nod.where=v;
nod.qu=w;
t[u].push_back(nod);//t[u]增加了一个点为 v,权值为 w的nod
nod.where=u;
t[v].push_back(nod);//和上面装法一样
}
for(int i=1;i<=n;i++){
now=0;//now为0是因为从点开始是没有值的
dfs(i);
}
cout<<minn;//输出
return 0;
}