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>
#define f first
#define s second
using namespace std;
#define MAX_N 100000
static int A[MAX_N];
static int B[MAX_N];
static int T[MAX_N];
const int N=1e5+5;
vector<pair<int,int> > V[N];
vector<int>a;
int fix[N],st[N],MxR,Mxr,mx,ans,Mx,h[N][2],R;
void dfs(int u,int p,int t){
fix[u]=1;
if(h[u][t]>mx) {
mx=h[u][t]; Mx=u;
}
for(int i=0;i<V[u].size();i++){
if(V[u][i].f!=p) {
h[V[u][i].f][t]=h[u][t]+V[u][i].s;
dfs(V[u][i].f,u,t);
}
}
}
void dfs1(int u,int p){
R=min(R,max(h[u][0],h[u][1]));
for(int i=0;i<V[u].size();i++){
if(V[u][i].f!=p){
dfs1(V[u][i].f,u);
}
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
//cout<<N
for(int i=0;i<M;i++){
V[A[i]].push_back({B[i],T[i]});
V[B[i]].push_back({A[i],T[i]});
}
for(int i=0;i<N;i++){
if(!fix[i]){
mx=0;
dfs(i,-1,0);
mx=0; R=1e8;
h[Mx][0]=0;
dfs(Mx,-1,0);// cout<<mx<<"_"<<R<<endl;
ans=max(ans,mx);
dfs(Mx,-1,1);
dfs1(i,-1);
a.push_back(R);
}
}
sort(a.begin(),a.end());
reverse(a.begin(),a.end());
if(a.size()>=3){
ans=max(ans,a[1]+a[2]+2*L);
}
if(a.size()>=2) ans=max(ans,a[0]+a[1]+L);
return ans;
}/*
int main() {
int N, M, L, i;
int res;
cin>>N>>M>>L;
for (i = 0; i < M; i++)
cin>>A[i]>>B[i]>>T[i];
int answer = travelTime(N, M, L, A, B, T);
printf("%d\n", answer);
return 0;
} */
Compilation message (stderr)
dreaming.cpp: In function 'void dfs(int, int, int)':
dreaming.cpp:21:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i=0;i<V[u].size();i++){
| ~^~~~~~~~~~~~
dreaming.cpp: In function 'void dfs1(int, int)':
dreaming.cpp:30:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i=0;i<V[u].size();i++){
| ~^~~~~~~~~~~~
dreaming.cpp: At global scope:
dreaming.cpp:10:12: warning: 'T' defined but not used [-Wunused-variable]
10 | static int T[MAX_N];
| ^
dreaming.cpp:9:12: warning: 'B' defined but not used [-Wunused-variable]
9 | static int B[MAX_N];
| ^
dreaming.cpp:8:12: warning: 'A' defined but not used [-Wunused-variable]
8 | static int A[MAX_N];
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |