# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
104070 | pedro_sponchiado | Dreaming (IOI13_dreaming) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
vector<int> adj[maxn], peso[maxn];
int raio1, raio2;
int dist[maxn], pai[maxn];
int marc[maxn];
void dfs(int u){
marc[u]=1;
for(int i=0; i<adj[u].size(); i++){
int v=adj[u][i];
if(v!=pai[u]){
pai[v]=u;
dist[v]=dist[u]+peso[u][i];
dfs(v);
}
}
return;
}
pair<int, int> proximos_raios(int a){
dist[a]=0;
dfs(a);
int maxi, maior1;
for(int i=1; i<=n; i++){
if(maxi<dist[i]){
maior1=i;
maxi=dist[i];
}
}
dist[maior1]=0;
dfs(maior1);
maxi=0;
for(int i=1; i<=n; i++){
if(maxi<dist[i]){
maior2=i;
maxi=dist[i];
}
}
int at=maior2;
pair<int, int> resp;
while(at!=maior1){
if(max(resp.first, resp.second)> max(dist[at], dist[maior2]-dist[at]) ){
resp=make_pair(dist[at], dist[maior2]-dist[at]);
}
}
if(resp.first>resp.second) swap(resp.first, resp.second);
return resp;
}
int travelTime(int n, int m, int l, int A[], int B[], int T[]) {
for(int i=0; i<m; i++){
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
peso[A[i]].push_back(T[i]);
peso[B[i]].push_back(T[i]);
}
raio1=-1;
for(int i=0; i<n; i++){
if(marc[i]==0){
pair<int, int> p=proximos_raios(i);
if(raio1==-1){
raio1=p.first;
raio2=p.second;
continue;
}
if(raio2>p.second){
raio1=raio2;
raio2=max(p.second+l, raio1);
}
else{
raio1=p.second;
raio2=max(raio2+l, p.first);
}
if(raio1>raio2) swap(raio1, raio2);
}
}
return raio1+raio2;
}