#include "dreaming.h"
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string.h>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <set>
#include <deque>
#include <utility>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <math.h>
#include <algorithm>
#include <limits.h>
using namespace std ;
const int N = 1e5+2;
#define ff first
#define ss second
#define pb push_back
vector <int> ans, cur ;
int best = 0 ;
int visit[N];
vector <pair<int,int> > G[N] ;
int node = 0 ;
map <pair<int,int>, int > dis ;
void fnd ( int u, int p, int d, int flag ) {
cur.push_back ( u ) ;
visit[u] = 1;
for ( auto v:G[u] ) {
if ( v.ff == p ) continue ;
fnd ( v.ff, u, d + v.ss, flag ) ;
}
if ( d >= best ) {
best = d;
if ( flag && u == node ) ans = cur ;
if ( !flag ) node = u ;
}
cur.pop_back() ;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for ( int i = 0 ; i < M ; ++i ) G[A[i]].pb ( make_pair (B[i], T[i]) ), G[B[i]].pb ( make_pair(A[i], T[i]) ), dis[make_pair(A[i], B[i])] = dis[make_pair(B[i],A[i])] = T[i] ;
vector <int> toAn ;
for ( int i = 0 ; i < N ; ++i ) {
if ( visit[i] ) continue;
best = 0 ;
fnd ( i, -1, 0,0 ) ;
best = 0 ;
int nod = node ;
fnd ( nod, -1, 0,0 ) ;
fnd ( nod,-1,0,1) ;
vector <int> diLeft, diRg ;
diLeft.push_back (0) ;
diRg.push_back (0) ;
int lft = 0, rg = 0 ;
for ( int j = 1 ; j < ans.size() ; ++j ) {
lft += dis [ make_pair(ans[j], ans[j-1]) ] ;
diLeft.push_back(lft) ;
}
int sz = ans.size() ;
for ( int j = sz-2 ; j >= 0 ; --j ) {
rg += dis[make_pair(ans[j], ans[j+1])] ;
diRg.push_back (rg) ;
}
reverse ( diRg.begin(), diRg.end() ) ;
int an = INT_MAX ;
for ( int i = 0 ; i < ans.size() ; ++i ) {
an = min ( an, max (diRg[i], diLeft[i]) ) ;
}
toAn.push_back ( an );
}
sort ( toAn.begin(), toAn.end() ) ;
int mx = toAn.back() + L ;
toAn.pop_back() ;
mx += toAn.back() ;
int scP = toAn.back() + 2 * L ;
if ( toAn.size() == 1 ) return mx ;
toAn.pop_back() ;
scP += toAn.back() ;
return max ( scP, mx ) ;
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:66:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for ( int j = 1 ; j < ans.size() ; ++j ) {
~~^~~~~~~~~~~~
dreaming.cpp:77:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for ( int i = 0 ; i < ans.size() ; ++i ) {
~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
294 ms |
26096 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
294 ms |
26096 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
294 ms |
26096 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
9720 KB |
Output is correct |
2 |
Correct |
103 ms |
9848 KB |
Output is correct |
3 |
Correct |
118 ms |
9720 KB |
Output is correct |
4 |
Correct |
108 ms |
9764 KB |
Output is correct |
5 |
Correct |
113 ms |
9752 KB |
Output is correct |
6 |
Correct |
134 ms |
10396 KB |
Output is correct |
7 |
Correct |
97 ms |
10104 KB |
Output is correct |
8 |
Correct |
87 ms |
9552 KB |
Output is correct |
9 |
Correct |
84 ms |
9464 KB |
Output is correct |
10 |
Correct |
98 ms |
9848 KB |
Output is correct |
11 |
Correct |
6 ms |
2688 KB |
Output is correct |
12 |
Correct |
21 ms |
3836 KB |
Output is correct |
13 |
Correct |
19 ms |
3840 KB |
Output is correct |
14 |
Correct |
20 ms |
3708 KB |
Output is correct |
15 |
Correct |
19 ms |
3712 KB |
Output is correct |
16 |
Correct |
19 ms |
3708 KB |
Output is correct |
17 |
Correct |
19 ms |
3708 KB |
Output is correct |
18 |
Correct |
20 ms |
3836 KB |
Output is correct |
19 |
Correct |
19 ms |
3708 KB |
Output is correct |
20 |
Incorrect |
6 ms |
2688 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
294 ms |
26096 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
294 ms |
26096 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |