# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
900546 | 2024-01-08T13:49:00 Z | JakobZorz | Dreaming (IOI13_dreaming) | C++17 | 0 ms | 0 KB |
#include"dreaming.h" #include<iostream> #include<vector> using namespace std; int n,m,l; vector<pair<int,int>>nodes[100000]; bool vis[100000]; vector<int>node_list; void dfs(int node){ if(vis[node]) return; vis[node]=true; node_list.push_back(node); for(auto ne:nodes[node]) dfs(ne.first); } int get_max_dist(int node,int prev){ int res=0; for(auto ne:nodes[node]){ if(ne.first==prev) continue; res=max(res,get_max_dist(ne.first,node)+ne.second); } return res; } int get_diameter(int root){ node_list.clear(); dfs(root); int res=2e9; for(int node:node_list){ res=min(res,get_max_dist(node,node)); } return 0; } int travelTime(int N,int M,int L,int A[],int B[],int T[]){ n=N; m=M; l=L; for(int i=0;i<m;i++){ nodes[A[i]].emplace_back(B[i],T[i]); nodes[B[i]].emplace_back(A[i],T[i]); } vector<int>dists; cout<<n<<endl; for(int i=0;i<n;i++){ if(!vis[i]){ dists.push_back(get_diameter(i)); } } sort(dists.begin(),dists.end()); reverse(dists.begin(),dists.end()); if(dists.size()==1) return dists[0]; else return dists[0]+dists[1]+l; }