# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
416239 | Runtime_error_ | Cheap flights (LMIO18_pigus_skrydziai) | C++14 | 1798 ms | 113420 KiB |
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 ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const ll inf = 3e5+9;
ll n,m,ans;
vector<pair<ll,ll> > adj[inf];
map<ll,ll> edge[inf];
int main(){
scanf("%lld%lld",&n,&m);
for(ll i=1;i<=m;i++){
ll u,v,w;
scanf("%lld%lld%lld",&u,&v,&w);
adj[u].pb(mp(w,v));
adj[v].pb(mp(w,u));
edge[u][v] = edge[v][u] = w;
}
for(ll i=1;i<=n;i++){
sort(adj[i].rbegin(),adj[i].rend());
ll sum = 0;
for(auto o:adj[i])
sum += o.first;
ans = max(ans,sum);
if(adj[i].size() > 1){
auto u = adj[i][0],v = adj[i][1];
ans = max(ans,u.first+v.first+edge[u.second][v.second]);
}
}
printf("%lld\n",ans);
}
Compilation message (stderr)
# | 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... |