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;
int ans , maxx , x , y ;
int pare [ 1000005 ] ;
int a [ 1000005 ] ;
vector < pair < int , int > > vc [ 1000005 ] ;
vector < int > vec ;
bool used [ 1000005 ] ;
pair < int , int > dfs ( int chi , int par ) {
used [ chi ] = 1 ;
pair < int , int > prr = { 0 , chi } ;
for( auto &u : vc [ chi ] ) {
if ( u . second == par ) continue;
pair < int , int > pp = dfs ( u . second , chi ) ;
prr = max ( prr , { pp . first + u . first , pp . second } ) ;
}
a [ chi ] = prr . first ;
pare [ chi ] = par ;
return prr ;
}
int travelTime (int N, int M, int L, int A[], int B[], int T[]) {
for ( int i = 0 ; i < M ; i ++ ) {
vc [ A [ i ] ] . push_back ( { T [ i ] , B [ i ] } ) ;
vc [ B [ i ] ] . push_back ( { T [ i ] , A [ i ] } ) ;
}
for ( int i = 0 ; i < N ; i ++ ) {
if ( used [ i ] != 0 ) continue ;
pair < int , int > pr = dfs ( dfs ( i , -1 ) . second , -1 ) ;
x = pr . second ;
y = pr . first ;
for ( int j = x ; j >= 0 ; j = pare [ j ] ) {
y = min ( y , max ( a [ j ] , pr . first - a [ j ] ) ) ;
}
vec . push_back ( y ) ;
maxx = max ( maxx , pr. first ) ;
}
sort ( vec . rbegin ( ) , vec . rend ( ) ) ;
if ( vec . size ( ) > 2 ) {
ans = L + vec [ 0 ] + vec [ 1 ] ;
for ( int i = 2 ; i < vec . size ( ) ; i ++ ) {
ans = max ( ans , L + L + vec [ 1 ] + vec [ i ] ) ;
}
}
else {
if ( vec . size ( ) == 2 ) ans = L + vec [ 0 ] + vec [ 1 ] ;
else ans = 0 ;
}
ans = max ( ans , maxx ) ;
return ans ;
}
Compilation message (stderr)
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:44:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for ( int i = 2 ; i < vec . 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... |