#include<iostream>
#include<vector>
#include<map>
#include<bitset>
#define ll 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::bitset<NMAX>f;
ll ans=0;
int n, m;
void dfs(int node, int parent)
{
f[node]=true;
for(auto next:G[node])
{
if(mp[{next, node}] && mp[{parent, node}] && mp[{next, parent}])//triunghi
ans=std::max(ans, mp[{next, node}]+mp[{next,parent}]+mp[{node,parent}]);
if(!f[next])
dfs(next, 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;
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(!f[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... |