제출 #1139394

#제출 시각아이디문제언어결과실행 시간메모리
1139394teo_55Cheap flights (LMIO18_pigus_skrydziai)C++20
0 / 100
291 ms45972 KiB
#include<iostream> #include<vector> #include<map> #define ll long long const int NMAX=500005; std::vector<ll>v(NMAX); std::map<std::pair<int, int>, ll>mp; std::vector<int>G[NMAX]; std::vector<int>dep(NMAX); ll ans=0; int n, m; void dfs(int node, int parent) { for(auto it:G[node]) { int next=it; if(dep[next]==0) { dep[next]=dep[node]+1; dfs(next, node); } else if(dep[next]+2==dep[node])//triunghi ans=std::max(ans, mp[{std::min(next, node), std::max(next, node)}]+mp[{std::min(next, parent),std::max(next, parent)}]+mp[{std::min(parent, node),std::max(parent, node)}]); } } int main() { std::cin>>n>>m; for(int i=0; i<m; ++i) { int from, to, cost; std::cin>>from>>to>>cost; v[from]+=cost; v[to]+=cost; if(from>to) std::swap(from, to); mp[{from, to}]=cost; G[from].push_back(to); G[to].push_back(from); } for(int i=1; i<=n; ++i) ans=std::max(ans, v[i]); for(int i=1; i<=n; ++i) if(!dep[i]) { dep[i]=1; dfs(1, 0); } std::cout<<ans; 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...