This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std ;
const int MAX = 5e5 + 10 ;
int vis[MAX] , mark[MAX] ;
int n , m ;
vector< vector< pair<int , int> > >adj(MAX) ;
long long ans = 0ll ;
map< pair<int , int> , int>mp ;
void dfs(int node , int par , long long x)
{
vis[node] = mark[node] = 1 ;
long long sum = 0 ;
for(auto &child : adj[node])
{
if(child.first != par)
ans = max(ans , x + child.second) ;
int to = child.first ;
sum += child.second ;
if(vis[to])
{
if(mark[to] && mp.find({par , to}) != mp.end())
ans = max(ans , x + child.second + mp[{par , to}]) ;
continue ;
}
dfs(to , node , child.second) ;
}
ans = max(ans , sum) ;
mark[node] = 0 ;
}
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>m ;
for(int i = 0 ; i < m ; ++i)
{
int x , y , z ;
cin>>x>>y>>z ;
mp[{x , y}] = mp[{y , x}] = z ;
adj[x].emplace_back(y , z) ;
adj[y].emplace_back(x , z) ;
}
for(int i = 1 ; i <= n ; ++i)
{
if(!vis[i])
dfs(i , 0 , 0) ;
}
return cout<<ans<<"\n" , 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... |