#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 547
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll inf=1e18;
const ld pai=acos(-1);
#include "dreaming.h"
int n , m ;
vpi v[100009] , trees;
int done[100009];
int dpdn[100009] , dpup[100009] ;
vi nodes;
void who ( int node , int p ) {
done [ node ] = 1 ;
nodes.pb ( node ) ;
for ( auto u : v [ node ] ) {
if ( u.fi == p ) C ;
who ( u.fi , node ) ;
}
}
void dfsdn ( int node , int p ) {
for ( auto u : v[node] ) {
if ( u.fi == p ) C ;
dfsdn ( u.fi , node ) ;
dpdn[node] = max ( dpdn[node] , dpdn[u.fi] + u.se ) ;
}
}
void dfsup ( int node , int p ) {
pi mx1 , mx2 ;
mx1 = mx2 = { -1 , -1 } ;
for ( auto U : v[node] ) {
int u = U.fi ;
int x = U.se ;
if ( u == p ) C ;
pi ret = { dpdn[u] + x , u } ;
if ( ret.fi > mx1.fi ) {
swap ( mx1 , mx2 ) ;
mx1 = ret ;
}
else mx2 = max ( mx2 , ret ) ;
}
for ( auto U : v[node] ) {
int u = U.fi ;
int x = U.se ;
if ( u == p ) C ;
int MX= dpup[node];
if ( mx1.se != u ) MX = max ( MX , mx1.fi ) ;
else MX = max ( MX , mx2.fi ) ;
dpup[u] = MX + x ;
dfsup( u , node ) ;
}
}
void fill ( int node ) {
nodes.clear() ;
who ( node , node ) ;
for ( auto u : nodes ) dpdn[u] = dpup[u] = 0 ;
dfsdn ( node , node ) ;
dfsup ( node , node ) ;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
n = N , m = M ;
for ( int i = 0 ; i < m ; i ++ ) {
int a = A[i] ;
int b = B[i] ;
int c = T[i] ;
v[a].pb ( { b , c } ) ;
v[b].pb ( { a , c } ) ;
}
for ( int i = 1 ; i < n ; i ++ ) {
if ( done [i] ) C ;
fill ( i ) ;
pi mn = { 1e9 , 1e9 } ;
for ( auto u : nodes ) {
mn = min ( mn , { max ( dpdn[u] , dpup[u] ) , u } ) ;
}
if ( mn.se == 1e9 ) while ( 1 ) { }
trees .pb ( mn ) ;
}
sort ( trees.begin() , trees.end() ) ;
for ( int i = 0 ; i < trees.size() - 1 ; i ++ ) {
int a = trees[i].se;
int b = trees.back().se;
v[a] .pb ( { b , L } ) ;
v[b] .pb ( { a , L } ) ;
}
fill ( 0 ) ;
int mx = 0 ;
// if ( nodes.size() != n ) while ( 1 ) { }
for ( auto u : nodes ) mx = max ( mx , dpdn[u] + dpup[u] ) ;
return mx ;
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:101:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for ( int i = 0 ; i < trees.size() - 1 ; i ++ ) {
~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
15732 KB |
Output is correct |
2 |
Correct |
84 ms |
17396 KB |
Output is correct |
3 |
Correct |
66 ms |
11900 KB |
Output is correct |
4 |
Correct |
15 ms |
4352 KB |
Output is correct |
5 |
Correct |
13 ms |
3712 KB |
Output is correct |
6 |
Correct |
23 ms |
6016 KB |
Output is correct |
7 |
Correct |
6 ms |
2816 KB |
Output is correct |
8 |
Correct |
45 ms |
7416 KB |
Output is correct |
9 |
Correct |
58 ms |
10104 KB |
Output is correct |
10 |
Correct |
6 ms |
2816 KB |
Output is correct |
11 |
Correct |
83 ms |
11800 KB |
Output is correct |
12 |
Correct |
116 ms |
14960 KB |
Output is correct |
13 |
Correct |
7 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
15732 KB |
Output is correct |
2 |
Correct |
84 ms |
17396 KB |
Output is correct |
3 |
Correct |
66 ms |
11900 KB |
Output is correct |
4 |
Correct |
15 ms |
4352 KB |
Output is correct |
5 |
Correct |
13 ms |
3712 KB |
Output is correct |
6 |
Correct |
23 ms |
6016 KB |
Output is correct |
7 |
Correct |
6 ms |
2816 KB |
Output is correct |
8 |
Correct |
45 ms |
7416 KB |
Output is correct |
9 |
Correct |
58 ms |
10104 KB |
Output is correct |
10 |
Correct |
6 ms |
2816 KB |
Output is correct |
11 |
Correct |
83 ms |
11800 KB |
Output is correct |
12 |
Correct |
116 ms |
14960 KB |
Output is correct |
13 |
Correct |
7 ms |
2816 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
6 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
6 ms |
2688 KB |
Output is correct |
18 |
Correct |
6 ms |
2688 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Correct |
6 ms |
2688 KB |
Output is correct |
21 |
Correct |
6 ms |
2688 KB |
Output is correct |
22 |
Correct |
6 ms |
2688 KB |
Output is correct |
23 |
Correct |
6 ms |
2688 KB |
Output is correct |
24 |
Correct |
6 ms |
2688 KB |
Output is correct |
25 |
Correct |
6 ms |
2688 KB |
Output is correct |
26 |
Correct |
6 ms |
2688 KB |
Output is correct |
27 |
Correct |
6 ms |
2688 KB |
Output is correct |
28 |
Incorrect |
6 ms |
2688 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
15732 KB |
Output is correct |
2 |
Correct |
84 ms |
17396 KB |
Output is correct |
3 |
Correct |
66 ms |
11900 KB |
Output is correct |
4 |
Correct |
15 ms |
4352 KB |
Output is correct |
5 |
Correct |
13 ms |
3712 KB |
Output is correct |
6 |
Correct |
23 ms |
6016 KB |
Output is correct |
7 |
Correct |
6 ms |
2816 KB |
Output is correct |
8 |
Correct |
45 ms |
7416 KB |
Output is correct |
9 |
Correct |
58 ms |
10104 KB |
Output is correct |
10 |
Correct |
6 ms |
2816 KB |
Output is correct |
11 |
Correct |
83 ms |
11800 KB |
Output is correct |
12 |
Correct |
116 ms |
14960 KB |
Output is correct |
13 |
Correct |
7 ms |
2816 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
6 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
6 ms |
2688 KB |
Output is correct |
18 |
Correct |
6 ms |
2688 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Correct |
6 ms |
2688 KB |
Output is correct |
21 |
Correct |
6 ms |
2688 KB |
Output is correct |
22 |
Correct |
6 ms |
2688 KB |
Output is correct |
23 |
Correct |
6 ms |
2688 KB |
Output is correct |
24 |
Correct |
6 ms |
2688 KB |
Output is correct |
25 |
Correct |
6 ms |
2688 KB |
Output is correct |
26 |
Correct |
6 ms |
2688 KB |
Output is correct |
27 |
Correct |
6 ms |
2688 KB |
Output is correct |
28 |
Incorrect |
6 ms |
2688 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
8816 KB |
Output is correct |
2 |
Incorrect |
37 ms |
8308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
15732 KB |
Output is correct |
2 |
Correct |
84 ms |
17396 KB |
Output is correct |
3 |
Correct |
66 ms |
11900 KB |
Output is correct |
4 |
Correct |
15 ms |
4352 KB |
Output is correct |
5 |
Correct |
13 ms |
3712 KB |
Output is correct |
6 |
Correct |
23 ms |
6016 KB |
Output is correct |
7 |
Correct |
6 ms |
2816 KB |
Output is correct |
8 |
Correct |
45 ms |
7416 KB |
Output is correct |
9 |
Correct |
58 ms |
10104 KB |
Output is correct |
10 |
Correct |
6 ms |
2816 KB |
Output is correct |
11 |
Correct |
83 ms |
11800 KB |
Output is correct |
12 |
Correct |
116 ms |
14960 KB |
Output is correct |
13 |
Correct |
7 ms |
2816 KB |
Output is correct |
14 |
Correct |
7 ms |
2816 KB |
Output is correct |
15 |
Correct |
7 ms |
2816 KB |
Output is correct |
16 |
Correct |
8 ms |
2944 KB |
Output is correct |
17 |
Correct |
6 ms |
2816 KB |
Output is correct |
18 |
Correct |
7 ms |
2816 KB |
Output is correct |
19 |
Correct |
8 ms |
2944 KB |
Output is correct |
20 |
Correct |
7 ms |
2816 KB |
Output is correct |
21 |
Correct |
8 ms |
2816 KB |
Output is correct |
22 |
Correct |
9 ms |
2944 KB |
Output is correct |
23 |
Correct |
6 ms |
2688 KB |
Output is correct |
24 |
Correct |
6 ms |
2688 KB |
Output is correct |
25 |
Correct |
6 ms |
2688 KB |
Output is correct |
26 |
Correct |
6 ms |
2688 KB |
Output is correct |
27 |
Correct |
7 ms |
2688 KB |
Output is correct |
28 |
Incorrect |
6 ms |
2688 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
15732 KB |
Output is correct |
2 |
Correct |
84 ms |
17396 KB |
Output is correct |
3 |
Correct |
66 ms |
11900 KB |
Output is correct |
4 |
Correct |
15 ms |
4352 KB |
Output is correct |
5 |
Correct |
13 ms |
3712 KB |
Output is correct |
6 |
Correct |
23 ms |
6016 KB |
Output is correct |
7 |
Correct |
6 ms |
2816 KB |
Output is correct |
8 |
Correct |
45 ms |
7416 KB |
Output is correct |
9 |
Correct |
58 ms |
10104 KB |
Output is correct |
10 |
Correct |
6 ms |
2816 KB |
Output is correct |
11 |
Correct |
83 ms |
11800 KB |
Output is correct |
12 |
Correct |
116 ms |
14960 KB |
Output is correct |
13 |
Correct |
7 ms |
2816 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
6 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
6 ms |
2688 KB |
Output is correct |
18 |
Correct |
6 ms |
2688 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Correct |
6 ms |
2688 KB |
Output is correct |
21 |
Correct |
6 ms |
2688 KB |
Output is correct |
22 |
Correct |
6 ms |
2688 KB |
Output is correct |
23 |
Correct |
6 ms |
2688 KB |
Output is correct |
24 |
Correct |
6 ms |
2688 KB |
Output is correct |
25 |
Correct |
6 ms |
2688 KB |
Output is correct |
26 |
Correct |
6 ms |
2688 KB |
Output is correct |
27 |
Correct |
6 ms |
2688 KB |
Output is correct |
28 |
Incorrect |
6 ms |
2688 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |