#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl "\n"
#define vec vector<ll>
#define vecvec vector<vector<ll>>
using namespace std;
/*#define FileName ""
string Ghhhh = ".in";
string Ghhhhh = ".out";
ifstream Girdi(FileName + Ghhhh);
ofstream Cikti(FileName + Ghhhhh);
#define cin Girdi
#define cout Cikti*/
#define maxn 300005
ll n,m,ans = 0;
vector<ll> profit;
vector<vector<pair<ll,ll>>> adj;
vector<bool> vis;
map<pair<ll,ll>,ll> mapp;
inline void dfs(ll node, ll parent, ll edge){
vis[node] = 1;
for(auto go : adj[node]){
if(go.first == parent) continue;
if(mapp[{go.first,parent}] > 0){
ans = max(ans,go.second + edge + mapp[{go.first,parent}]);
}
if(!vis[go.first]) dfs(go.first,node,go.second);
}
}
inline void solve(){
cin >> n >> m;
adj.resize(n+1);
vis.resize(n+1,0);
profit.resize(n+1,0);
while(m--){
ll a,b,c;
cin >> a >> b >> c;
profit[a] += c;
profit[b] += c;
adj[a].pb({b,c});
adj[b].pb({a,c});
mapp[{a,b}] = c;
mapp[{b,a}] = c;
}
dfs(1,-1,0);
for(ll i = 1 ; i <= n ; i++){
ans = max(ans,profit[i]);
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll t = 1;
//cin >> t;
while(t--){
solve();
}
}
# | 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... |