Submission #973562

#TimeUsernameProblemLanguageResultExecution timeMemory
973562AtabayRajabliCheap flights (LMIO18_pigus_skrydziai)C++17
100 / 100
1242 ms99924 KiB
#include <bits/stdc++.h> #define int ll #define all(v) v.begin(), v.end() // author : a1abay using namespace std; typedef long long ll; typedef long double ld; const int sz = 3e5 + 5; const int inf = 1e9 + 7; int n, m, ans, u, v, w; vector<array<int, 2>> g[sz]; map<array<int, 2>, int> e; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 1; i <= m; i++) { cin >> u >> v >> w; g[u].push_back({w, v}); g[v].push_back({w, u}); e[{u, v}] = w; e[{v, u}] = w; } for(int i = 1; i <= n; i++) { sort(all(g[i])); reverse(all(g[i])); int s = 0; for(auto p : g[i]) s += p[0]; ans = max(ans, s); } for(int i = 1; i <= n; i++) { if(g[i].size() < 2) continue; if(!e[{g[i][0][1], g[i][1][1]}]) continue; ans = max(ans, g[i][0][0] + g[i][1][0] + e[{g[i][0][1], g[i][1][1]}]); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...