代码
#include <bits/stdc++.h>
using namespace std ;
int n , a[30][30] , m , x , y , f , ans , mans ;
bool A[114] ;//初始值为false
void dfs( int x , int ans){
A[x] = true ;//进入后将其标记为true
bool z = false ;
for( int i = 1 ; i <= n ; i ++ ){
if(a[i][x] != 0 && A[i] == false ){
z = true ;
ans+= a[i][x];
// cout<<"test: "<<x<<"->"<<i<<endl;
if( ans > mans ){
mans = ans ;
}
dfs( i , ans );
z = false ;
}
}
for( int i = 1 ; i <= n ; i ++ ){
if(a[x][i] != 0 && A[i] == false ){
z = true ;
ans+= a[x][i];
// cout<<"test: "<<x<<"->"<<i<<endl;
if( ans > mans ){
mans = ans ;
}
dfs( i , ans );
z = false ;
}
}
return ;
}
int main(){
//输入
scanf("%d %d" , &n , &m);
for( int i = 1 ; i <= m ; i ++ ){
cin >> x >> y >> f ;
a[x][y] = f ;
a[y][x] = f ;
}
//枚举出发点
for( int i = 1 ; i <= n ; i ++ ){
ans = 0 ;
memset(A,false,sizeof(A));
dfs(i , 0);
}
cout << mans << endl;
return 0 ;
}
感谢大佬帮助, 好人一生平安sto