#include<iostream>
#include<vector>
#include<map>
#define ll unsigned long long
#define int unsigned long long
const int NMAX=500005;
std::vector<ll>v(NMAX);
std::map<std::pair<int, int>, ll>mp;
std::vector<int>G[NMAX];
std::vector<int>dep(NMAX);
ll ans=0;
int n, m;
void dfs(int node, int parent)
{
dep[node]=dep[parent]+1;
for(auto next:G[node])
{
if(dep[next]==0)
dfs(next, node);
else if(dep[next]+2==dep[node] && dep[next])//triunghi
ans=std::max(ans, mp[{next, node}]+mp[{next,parent}]+mp[{node,parent}]);
}
}
signed main()
{
std::cin>>n>>m;
for(int i=0; i<m; ++i)
{
int from, to, cost;
std::cin>>from>>to>>cost;
v[from]+=cost;
v[to]+=cost;
mp[{from, to}]=cost;
mp[{to, from}]=cost;
G[from].push_back(to);
G[to].push_back(from);
}
for(int i=1; i<=n; ++i)
ans=std::max(ans, v[i]);
for(int i=1; i<=n; ++i)
if(!dep[i])
dfs(i, 0);
std::cout<<ans;
return 0;
}
# | 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... |