#include <bits/stdc++.h>
using namespace std;
const int NMAX = 200;
int n, m;
vector <pair<int, long long>> graph[NMAX+1];
vector <int> sum(NMAX+1, 0), antecedent(NMAX+1, 0);
vector <vector<int>> mat;
int stea_max = 0;
bitset <NMAX+1> vis;
long long maxim(long long a, long long b)
{
if(a>=b)
return a;
return b;
}
void read()
{
int a, b, c;
cin>>n>>m;
mat.assign(n+1, vector<int>(n+1, -1));
for(int i=1; i<=m; i++)
{
cin>>a>>b>>c;
graph[a].push_back({b, c});
graph[b].push_back({a, c});
sum[a]+=c;
sum[b]+=c;
stea_max = maxim(stea_max, sum[a]);
stea_max = maxim(stea_max, sum[b]);
mat[a][b]=c;
mat[b][a]=c;
}
}
long long rez3;
void dfs(int node, int parent)
{
vis[node] = 1;
for(auto [next, price]:graph[node])
{
if(mat[next][parent]!=-1 && ( parent!=node) && next!=parent)//am detectat ciclu
{
rez3 = maxim(rez3, mat[next][node] + mat[parent][node] + mat[parent][next]);
}
else if(next!=parent)
{
dfs(next, node);
}
}
}
long long cicle3()
{
long long rez = 0;
for(int i=1; i<=n; i++)
{
if(vis[i]==0)
dfs(i, i);
}
return rez3;
}
int main()
{
read();
//cout<<stea_max<<" "<<cicle3();;//38 39
cout<<maxim( stea_max, cicle3());
return 0;
}
/*
oricare doua muchii trebuie sa aiba un nod in comun
apm
va fi ori stea ori triunghi
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |