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>
#define FLASH ios_base::sync_with_stdio(0);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
using namespace std;
unordered_map<ll,ll>adj1[300010];
vector<pair<ll,ll> >adj[300010];
ll sorthus(pair<ll,ll>a,pair<ll,ll>b)
{
return a.first>b.first;
}
ll n,m;
int main(){
FLASH;
cin>>n>>m;
for(ll i=1;i<=m;i++)
{
ll x,y,z;
cin>>x>>y>>z;
adj[x].pb(mp(z,y));
adj[y].pb(mp(z,x));
adj1[x][y]=z;
adj1[y][x]=z;
}
ll maxx=0;
ll summ=0;
for(ll i=1;i<=n;i++)
{
summ=0;
sort(all(adj[i]),sorthus);
for(auto j:adj1[i])summ+=j.second;
maxx=max(maxx,summ);
}
for(ll i=1;i<=n;i++)
{
if(adj[i].size()>=1)
{
auto one=adj[i][0];
if(adj[one.second].size()>=2)
{
auto two=adj[one.second][1];
maxx=max(maxx,one.first+two.first+adj1[two.second][i]);
}
}
}
cout<<maxx<<endl;
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... |