Submission #498534

#TimeUsernameProblemLanguageResultExecution timeMemory
498534KiprasCheap flights (LMIO18_pigus_skrydziai)C++14
53 / 100
386 ms60832 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; const ll maxN = 1e5*3+1; ll n, m; vector<pair<ll, ll>> adj[maxN]; vector<pair<ll, ll>> adjFast[maxN]; ll findVal(ll v, ll v1){ ll l = 0, h = adjFast[v1].size()-1; while(l<h){ ll mid = l+((h-l)/2); if(adjFast[v1][mid].first==v)return adjFast[v1][mid].second; else if(adjFast[v1][mid].first<v)l=mid+1; else h=mid-1; } return -1; } int main() { ios_base::sync_with_stdio(0);cin.tie(nullptr); cin>>n>>m; for(ll i = 0; i < m; i++){ ll a, b, c; cin>>a>>b>>c; adj[a].push_back({b, c}); adj[b].push_back({a, c}); adjFast[a].push_back({b, c}); adjFast[b].push_back({a, c}); } for(ll i = 1; i <= n; i++)sort(adjFast[i].begin(), adjFast[i].end()); ll ans=0; for(ll i = 1; i <= n; i++){ ll temp=0; for(auto x : adj[i]){ temp+=x.second; } ans=max(ans, temp); } for(ll i = 1; i <= n; i++){ for(ll x = 0; x < (ll)(adj[i].size())-1; x++){ ll temp=0; ll val=-1; ll v1=adj[i][x].first, v2=adj[i][x+1].first; val = findVal(v2, v1); if(val==-1)continue; temp=adj[i][x].second+adj[i][x+1].second+val; ans=max(ans, temp); } } cout<<ans; 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...