#include<iostream>
#include<vector>
#include<map>
#define ll 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[{std::min(next, node), std::max(next, node)}]+mp[{std::min(next, parent),std::max(next, parent)}]+mp[{std::min(parent, node),std::max(parent, node)}]);
}
}
int 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;
if(from>to)
std::swap(from, to);
mp[{from, to}]=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... |