제출 #1171216

#제출 시각아이디문제언어결과실행 시간메모리
1171216qrnCheap flights (LMIO18_pigus_skrydziai)C++20
100 / 100
1187 ms84020 KiB
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> using namespace std; // using namespace __gnu_pbds; #define SPEED \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); #define pb push_back #define ins insert #define fi first #define se second #define endl "\n" #define ALL(x) x.begin(), x.end() #define sz(x) x.size() #define intt long long const intt mod = 1e9 + 7; const intt base = 31; const intt inf = 1e9; const intt mxN = 500000 + 5; const intt L = 21; vector<vector<pair<intt,intt>>> graph; map<pair<intt,intt>,intt>cost; bool cmp(pair<intt,intt> &a, pair<intt,intt> &b) { if(a.se == b.se) return a.fi < b.fi; return a.se > b.se; } void solve() { intt n, m; cin >> n >> m; graph.assign(n + 1, vector<pair<intt,intt>> {}); for(intt i = 1; i <= m; i++) { intt a, b, w; cin >> a >> b >> w; graph[a].pb({b, w}); graph[b].pb({a, w}); cost[{a,b}] = cost[{b,a}] = w; } intt ans = 0; for(intt i = 1; i <= n; i++) { if(graph[i].size() == 0) continue; sort(ALL(graph[i]), cmp); intt forthis = 0; for(auto u : graph[i]) forthis += u.se; ans = max(ans, forthis); if(graph[i].size() == 1) continue; ans = max(ans, graph[i][0].se + graph[i][1].se + cost[{graph[i][0].fi, graph[i][1].fi}]); } cout << ans << endl; } signed main() { SPEED; intt tst = 1; // cin >> tst; while (tst--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...