#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
#include "dreaming.h"
pair<int,int> menormayor(vector<int>&d1,vector<int>&d2,vector<int>&d3,vector<vector<pair<int,int> > >&g,int raiz){
queue<int>cola;
cola.push(raiz);
int u=raiz,MAX=raiz;
d1[u]=0;
vector<int>cc;
while(!cola.empty()){
u=cola.front();
cola.pop();
cc.push_back(u);
if(d1[u]>d1[MAX])MAX=u;
for(pair<int,int>c:g[u]){
if(d1[c.first]>d1[u]+c.second){
d1[c.first]=d1[u]+c.second;
cola.push(c.first);
}
}
}
cola.push(MAX);
int MAX2=MAX;
d2[MAX]=0;
while(!cola.empty()){
u=cola.front();
cola.pop();
if(d2[u]>d2[MAX2])MAX2=u;
for(pair<int,int>c:g[u]){
if(d2[c.first]>d2[u]+c.second){
d2[c.first]=d2[u]+c.second;
cola.push(c.first);
}
}
}
cola.push(MAX2);
d3[MAX2]=0;
while(!cola.empty()){
u=cola.front();
cola.pop();
for(pair<int,int>c:g[u]){
if(d3[c.first]>d3[u]+c.second){
d3[c.first]=d3[u]+c.second;
cola.push(c.first);
}
}
}
int e=0;
for(int i=0;i<cc.size();i++){
e=min(e,max(d2[cc[i]],d3[cc[i]]));
}
return make_pair(e,MAX2);
}
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));
}
vector<int>d1(N,1e9);
vector<int>d2(N,1e9);
vector<int>d3(N,1e9);
vector<int>ecc,dia;
int CC=1;
for(int i=0;i<N;i++){
if(d1[i]==1e9){
pair<int,int>e=menormayor(d1,d2,d3,g,i);
ecc.push_back(e.first);
dia.push_back(e.second);
CC++;
}
}
int r=0;
for(int i=1;i<CC;i++){
if(ecc[i]>ecc[0]){
swap(ecc[i],ecc[0]);
}
}
if(CC>1){
for(int i=2;i<CC;i++){
if(ecc[i]>ecc[1])
swap(ecc[i],ecc[1]);
}
r=ecc[0]+ecc[1]+L;
}
if(CC>2){
for(int i=3;i<CC;i++){
if(ecc[i]>ecc[2])
swap(ecc[i],ecc[2]);
}
r=max(r,ecc[1]+ecc[2]+2*L);
}
for(int i=0;i<CC;i++){
r=max(r,dia[i]);
}
return r;
}
Compilation message
dreaming.cpp: In function 'std::pair<int, int> menormayor(std::vector<int>&, std::vector<int>&, std::vector<int>&, std::vector<std::vector<std::pair<int, int> > >&, int)':
dreaming.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i=0;i<cc.size();i++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
49 ms |
9636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
49 ms |
9636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
35 ms |
8500 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
49 ms |
9636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |