Submission #942160

#TimeUsernameProblemLanguageResultExecution timeMemory
942160MathiasCheap flights (LMIO18_pigus_skrydziai)C++14
100 / 100
1351 ms106560 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5+7; long long t[MAXN]; vector<pair<int,int> > v; vector<pair<long long,int> >g[MAXN]; map<pair<int,int>,long long>w; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m,a,b,c,s; long long res=0; cin>>n>>m; for(int i=1;i<=m;i++){ cin>>a>>b>>c; t[a]+=c; t[b]+=c; g[a].push_back({c,b}); g[b].push_back({c,a}); v.push_back({a,b}); w[{a,b}]=w[{b,a}]=c; } for(int i=1;i<=n;i++){ res=max(res,t[i]); } for(int i=1;i<=n;i++){ sort(g[i].begin(),g[i].end()); s=g[i].size(); if(g[i].size()>1) { res=max(res,g[i][s-1].first + g[i][s-2].first + w[{g[i][s-1].second,g[i][s-2].second}]); } } cout<<res<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...