Submission #373814

#TimeUsernameProblemLanguageResultExecution timeMemory
373814gustasonCheap flights (LMIO18_pigus_skrydziai)C++11
53 / 100
320 ms46700 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int maxN = 3e5 + 5; struct Pii { int a, w; }; vector<Pii> adj[maxN]; vector<char> col(maxN); vector<Pii> par(maxN); ll sum[maxN], mx = 0; void dfs(int v, int p) { col[v] = 1; for(auto u : adj[v]) { if (p == u.a) continue; if (col[u.a] == 0) { dfs(u.a, v); } else if (col[u.a] == 1) { if (par[par[u.a].a].a == v) { ll w = par[par[u.a].a].w + par[u.a].w + u.w; mx = max(mx, w); } } par[u.a] = {v, u.w}; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; for(int i = 0; i < m; i++) { int a, b, w; cin >> a >> b >> w; adj[a].push_back({b, w}); adj[b].push_back({a, w}); sum[a] += w; sum[b] += w; } for(int i = 1; i <= n; i++) { if (col[i] == 0) dfs(i, -1); } for(int i = 1; i <= n; i++) { mx = max(mx, sum[i]); } cout << mx << "\n"; 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...