Submission #1046348

#TimeUsernameProblemLanguageResultExecution timeMemory
1046348xnqsCheap flights (LMIO18_pigus_skrydziai)C++17
28 / 100
3070 ms53336 KiB
#include <iostream> #include <fstream> #include <vector> #include <queue> #include <utility> #include <algorithm> #include <set> int gs, edg; std::vector<std::set<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(b,c); adj_list[b].emplace(a,c); edges.emplace_back(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 for (const auto& [a, b, c] : edges) { int x = a; int y = b; if (adj_list[x].size()>adj_list[y].size()) { std::swap(x,y); } for (const auto& [i, w] : adj_list[x]) { auto it = adj_list[y].lower_bound(std::pair<int,int>(i,0)); if (it!=adj_list[y].end()&&it->first==i) { ans = std::max(ans,(int64_t)c+w+it->second); } } } 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...