#include <bits/stdc++.h>
using namespace std;
const int nx=3e5+5;
#define ll long long
ll n, m, u, v, w, dp[nx], mx, pw[nx], pa[nx], vs[nx], lvl[nx];
vector<pair<ll, ll>> d[nx];
void dfs(int u, int p)
{
lvl[u]=lvl[p]+1;
pa[u]=p;
vs[u]=1;
//cout<<"debug "<<u<<' '<<lvl[u]<<' '<<pa[u]<<' '<<pw[u]<<'\n';
for (auto [v, w]:d[u])
{
if (vs[v]&&lvl[u]==lvl[v]+2) mx=max(mx, w+pw[u]+pw[pa[u]]);
else if (!vs[v]) pw[v]=w, dfs(v, u);
}
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
for (int i=1; i<=m; i++) cin>>u>>v>>w, d[u].push_back({v, w}), d[v].push_back({u, w}), dp[u]+=w, dp[v]+=w;
for (int i=1; i<=n; i++) mx=max(mx, dp[i]);
for (int i=1; i<=n; i++) if (!vs[i]) dfs(i, i);
cout<<mx;
}
# | 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... |