玄关
  • 板块灌水区
  • 楼主lucy2012
  • 当前回复5
  • 已保存回复5
  • 发布时间2024/7/5 12:55
  • 上次更新2024/7/5 15:23:49
查看原帖
玄关
1252442
lucy2012楼主2024/7/5 12:55

最近点对这题有谁可以给我看一下吗?谢谢啦!这是我的代码,求调:

#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();
	for(int i=0;i<size;i++){
		if(vis[t[x][i].where]!=1){
			vis[t[x][i].where]=1;
		    now+=t[x][i].qu;
		    if(now<minn)
		        minn=now;
			dfs(t[x][i].where);
            now-=t[x][i].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);
    	nod.where=u;
    	t[v].push_back(nod);
	}
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));
		now=0;
		dfs(i);
	}
	cout<<minn;
    return 0;
}
2024/7/5 12:55
加载中...