30分
查看原帖
30分
1069816
Tsuki091117楼主2024/3/4 19:15
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,x,y,z,ans,res;
bool vis[100];
int cnt[100];
struct node{
	int x,y;
}to[100][100];
void dfs(int s){
	for(int i=1;i<=cnt[s];i++){
		if(!vis[to[s][i].x]){
			vis[to[s][i].x]=1;
			ans+=to[s][i].y;
			dfs(to[s][i].x);
			vis[to[s][i].x]=0;
			ans-=to[s][i].y;
//			cout<<ans<<"\n"; 
		}
	}
	res=max(res,ans);
	ans=0;
}
signed main(){
	ios::sync_with_stdio(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>x>>y>>z;
		to[x][++cnt[x]].x=y;
		to[x][cnt[x]].y=z;
		to[y][++cnt[y]].x=x;
		to[y][cnt[y]].y=z;
	}
	for(int i=1;i<=n;i++){
		vis[i]=1;
		dfs(i);
		vis[i]=0;
	}
	cout<<res;
	return 0;
}
2024/3/4 19:15
加载中...