Submission #247397

#TimeUsernameProblemLanguageResultExecution timeMemory
247397dolphingarlicCheap flights (LMIO18_pigus_skrydziai)C++14
0 / 100
350 ms47736 KiB
/* LMIO 2018 Pigus Skrydziai - We either take all edges incident to one node or we take a triangle - There are */ #include <bits/stdc++.h> #define FOR(i, x, y) for (int i = x; i < y; i++) typedef long long ll; using namespace std; ll prof[300001], max_triangle = 0; vector<pair<int, ll>> graph[300001]; map<pair<int, int>, ll> edges; bool visited[300001]; void dfs(int node) { visited[node] = true; for (pair<int, ll> i : graph[node]) { if (!visited[i.first]) { for (pair<int, ll> j : graph[i.first]) { max_triangle = max(max_triangle, i.second + j.second + edges[{node, j.first}]); } } } for (pair<int, ll> i : graph[node]) { if (!visited[i.first]) dfs(i.first); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; while (m--) { int a, b; ll v; cin >> a >> b >> v; prof[a] += v, prof[b] += v; graph[a].push_back({b, v}); graph[b].push_back({a, v}); edges[{a, b}] = edges[{b, a}] = v; } FOR(i, 1, n + 1) if (!visited[i]) dfs(i); cout << max(max_triangle, *max_element(prof + 1, prof + n + 1)); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...