# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
586080 | 2022-06-29T20:07:41 Z | MrDeboo | Dreaming (IOI13_dreaming) | C++17 | 0 ms | 0 KB |
#include "dreaming.h" #include <bits/stdc++.h> using namespace std; int travelTime(int n, int m, int l, int a[], int b[], int t[]){ vector<pair<int,int>>vct[n]; for(int i=0;i<m;i++){ vct[a[i]].push_back({b[i],t[i]}); vct[b[i]].push_back({a[i],t[i]}); } deque<int>v; vector<int>vis(n); for(int i=0;i<n;i++){ if(vis[i])continue; vis[i]=1; vector<int>vc={i}; { deque<int>dq={i}; while(dq.size()){ int a=dq.front(); a.pop_front(); for(auto &w:vct[a]){ if(!vis[w.first]){ vis[w.first]=1; dq.push_back(w.first); vc.push_back(w.first); } } } } int f=INT_MAX; for(auto &w:vc){ vector<bool>vv(n); deque<pair<int,int>>dq={{w,0}}; vv[w]=1; int g=0; while(dq.size()){ int a=dq.front().first,b=dq.front().second; dq.pop_front(); g=max(g,b); for(auto &j:vct[a]){ if(!vv[j.first]){ vv[j.first]=1; dq.push_back({j.first,j.second+b}); } } } f=min(f,g); } v.push_back(f); } while(v.size()>1){ sort(v.begin(),v.end()); v[1]=max(v[1],v[0]+l); v.pop_front(); } return v.back(); }