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 mx=500009;
typedef long long ll;
map<pair<int,int>,ll>mp;
vector<pair<int,ll>>adj[mx];
int n,m;
ll ans;
int vis[mx];
void dfs(int node,int par){
vis[node]=2;
for(auto it:adj[node]){
if(it.first==par){continue;}
if(vis[it.first]==2&&mp.find({par,it.first})!=mp.end()){
ans=max(ans,1LL*(it.second+mp[{it.first,par}]+mp[{node,par}]));
}else if(vis[it.first]){
continue;
}else{
dfs(it.first,node);
}
}
vis[node]=1;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie();
cin>>n>>m;
for(int i=0; i<m; i++)
{
int x,y,w;
cin>>x>>y>>w;
adj[x].push_back({y,w});
adj[y].push_back({x,w});
mp[{x,y}]=w;
mp[{y,x}]=w;
}
for(int i=1;i<=n;i++){
if(!vis[i]){
dfs(i,0);
}
ll tmp=0;
for(auto it:adj[i]){
tmp+=it.second;
}
ans=max(ans,tmp);
}
cout<<ans;
}
# | 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... |