Submission #1046390

#TimeUsernameProblemLanguageResultExecution timeMemory
1046390xnqsCheap flights (LMIO18_pigus_skrydziai)C++17
16 / 100
136 ms23352 KiB
#include <iostream> #include <fstream> #include <vector> #include <queue> #include <utility> #include <algorithm> #include <set> #include <unordered_map> int gs, edg; std::vector<std::vector<std::pair<int,int>>> adj_list; std::vector<std::tuple<int,int,int>> edges; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); std::cin >> gs >> edg; adj_list.resize(gs+1); for (int i = 0, a, b, c; i < edg; i++) { std::cin >> a >> b >> c; adj_list[a].emplace_back(b,c); adj_list[b].emplace_back(a,c); edges.emplace_back(std::min(a,b),std::max(a,b),c); } // try all star graphs int64_t ans = 0; for (int i = 1; i <= gs; i++) { int64_t cand = 0; for (const auto& [j, w] : adj_list[i]) { cand += w; } ans = std::max(ans,cand); } // try all "triangle" cycles std::sort(edges.begin(),edges.end()); for (int i = 1; i <= gs; i++) { std::sort(adj_list[i].begin(),adj_list[i].end(),[](const std::pair<int,int>& a, const std::pair<int,int>& b) { return a.second < b.second; }); if (adj_list[i].size()>=2) { auto [a, wa] = adj_list[i][0]; auto [b, wb] = adj_list[i][1]; auto it = std::lower_bound(edges.begin(),edges.end(),std::tuple<int,int,int>(std::min(a,b),std::max(a,b),0)); if (it!=edges.end()&&std::get<0>(*it)==std::min(a,b)&&std::get<1>(*it)==std::max(a,b)) { ans = std::max(ans, (int64_t)wa + wb + std::get<2>(*it)); } } } std::cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...