제출 #1139363

#제출 시각아이디문제언어결과실행 시간메모리
1139363mariacCheap flights (LMIO18_pigus_skrydziai)C++20
12 / 100
1506 ms84332 KiB
#include <bits/stdc++.h> using namespace std; const int NMAX = 5000; int n, m; vector <pair<int, long long>> graph[NMAX+1]; vector <int> sum(NMAX+1, 0); int stea_max = 0; bitset <NMAX+1> vis; map <pair<int, int>, int> mat; long long maxim(long long a, long long b) { if(a>=b) return a; return b; } void read() { int a, b, c; cin>>n>>m; for(int i=1; i<=m; i++) { cin>>a>>b>>c; graph[a].push_back({b, c}); graph[b].push_back({a, c}); sum[a]+=c; sum[b]+=c; stea_max = maxim(stea_max, sum[a]); stea_max = maxim(stea_max, sum[b]); mat[{a, b}] = c; mat[{b, a}] = c; } } long long rez3; void dfs(int node, int parent) { vis[node] = 1; for(auto [next, price]:graph[node]) { if( mat.find({next, parent})!=mat.end() && ( parent!=node) && next!=parent)//am detectat ciclu { rez3 = maxim(rez3, mat[{next, node}] + mat[{parent, node}] + mat[{parent, next}]); } else if(next!=parent && vis[next] == 0) { dfs(next, node); } } } long long cicle3() { long long rez = 0; for(int i=1; i<=n; i++) { if(vis[i]==0) dfs(i, i); } return rez3; } int main() { read(); cout<<maxim(stea_max, cicle3()); 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...