# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
400067 | 2021-05-07T09:53:25 Z | victoriad | Dreaming (IOI13_dreaming) | C++14 | 0 ms | 0 KB |
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <utility> #include <queue> #include <map> #include <iomanip> #include <fstream> using namespace std; void dfs(vector<int>&con,vector<vector<pair<int,int> > >&g,int nodo){ con[nodo]=1; for(pair<int,int>c: g[nodo]){ if(con[c.first]==0){ dfs(con,g,c.first); } } } int bfs(vector<vector<pair<int,int> > >&g,int r){ int a=0; vector<int>d(g.size(),1e9); queue<int>cola; cola.push(r); d[r]=0; while(!cola.empty()){ int na=cola.front(); cola.pop(); for(pair<int,int> c: g[na]){ if(d[c.first]>d[na]+c.second){ d[c.first]=d[na]+c.second; if(d[c.first]>a)a=d[c.first]; cola.push(c.first); } } } return a; } int menormayor(vector<int>&con,vector<vector<pair<int,int> > >&g,int n){ int f=1e9,s=1e9; for(int i=0;i<n;i++){ int a=bfs(g,i); if(con[i]==1){ if(a<f)f=a; } else{ if(a<s)s=a; } } return s+f; } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { vector<vector<pair<int,int> > >g(N); vector<int>con(N,0); for(int i=0;i<N;i++){ int a=A[i],b=B[i],c=T[i]; g[a].push_back(make_pair(b,c)); g[b].push_back(make_pair(a,c)); } if(M==N-2){ dfs(con,g,0); return menormayor(con,g,N)+L; } return 42; }