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 pb push_back
#define mp make_pair
#define ff first
#define ss second
using namespace std;
vector<long long>vec;
long long vis[100001],id,p=0,path,res=0;
long long cost[100001];
long long go[100001];
vector<pair<long long,long long> >adj[100001];
void dfsd(long long u,long v,long long w){
cost[u]=w;
if(w>path){
id=u;
path=w;
}
go[u]=v;
for(long long i=0;i<adj[u].size();i++){
long long f=adj[u][i].ff;
long long s=adj[u][i].ss;
if(f!=v){
dfsd(f,u,w+s);
}
}
}
void dfs(long long u,long long v,long long w){
vis[u]=1;
if(w>p){
id=u;
p=w;
}
for(long long i=0;i<adj[u].size();i++){
long long f=adj[u][i].ff;
long long s=adj[u][i].ss;
if(f!=v){
dfs(f,u,w+s);
}
}
}
int travelTime(int n, int m, int L, int a[], int b[], int t[]){
for(long long i=0;i<m;i++){
adj[a[i]].pb(mp((long long)b[i],(long long)t[i]));
adj[b[i]].pb(mp((long long)a[i],(long long)t[i]));
}
for(long long i=0;i<n;i++){
if(!vis[i]){
path=0;
p=0;
id=0;
dfs(i,-1,0);
dfsd(id,-1,0);
res=max(res,path);
long long ans=1e18;
while(id!=-1){
ans=min(ans,max(path-cost[id],cost[id]));
id=go[id];
}
vec.pb(ans);
}
}
sort(vec.begin(),vec.end());
if(vec.size()>=2) res=max(res,vec[vec.size()-1]+vec[vec.size()-2]+L);
if(vec.size()>2) res=max(res,vec[vec.size()-2]+vec[vec.size()-3]+2*L);
return res;
}
Compilation message (stderr)
dreaming.cpp: In function 'void dfsd(long long int, long int, long long int)':
dreaming.cpp:20:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(long long i=0;i<adj[u].size();i++){
| ~^~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs(long long int, long long int, long long int)':
dreaming.cpp:35:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(long long i=0;i<adj[u].size();i++){
| ~^~~~~~~~~~~~~~
# | 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... |