#include "dreaming.h"
#include <iostream>
#include <vector>
using namespace std;
const long long N=1e5+200;
vector<pair<long long,long long>> ma[N];
bool vis[N];
bool tp=0;
long long dp_down[N][2];
long long dp_up[N];
long long mxx[N];
long long n,m,l;
void dfs_down(long long x,long long p=-1)
{
vis[x]=1;
dp_down[x][0]=dp_down[x][1]=0;
for(auto [w,y]:ma[x])
{
if(y!=p)
{
dfs_down(y,x);
long long cur=dp_down[y][0]+w;
if(dp_down[x][0]<cur)
{
dp_down[x][1]=dp_down[x][0];
dp_down[x][0]=cur;
}
else if(dp_down[x][1]<cur)
{
dp_down[x][1]=cur;
}
}
}
// if(tp)
// {
// cout<<"For "<<x<<' '<<p<<endl;
// cout<<dp_down[x][0]<<' '<<dp_down[x][1]<<endl;
// }
}
long long vertex=-1;
long long dist=1e18;
long long cp=-1;
void fill()
{
for(int i=0;i<n;i++)
dp_up[i]=0;
}
void dfs_up(long long x,long long p=-1)
{
mxx[x]=max(dp_up[x],dp_down[x][0]);
cp=max(cp,mxx[x]);
// if(tp)
// {
// cout<<"For "<<x<<' '<<mxx[x]<<endl;
// }
if(mxx[x]<dist)
{
dist=mxx[x];
vertex=x;
}
for(auto [w,y]:ma[x])
{
if(y!=p)
{
dp_up[y]=dp_up[x]+w;
if(dp_down[x][0]==(dp_down[y][0]+w))
dp_up[y]=max(dp_up[y],dp_down[x][1]+w);
else
dp_up[y]=max(dp_up[y],dp_down[x][0]+w);
dfs_up(y,x);
}
}
}
int travelTime(int N, int M, int L, int a[], int b[], int t[])
{
n=N;
m=M;
l=L;
for(int i=0;i<m;i++)
{
ma[a[i]].push_back({t[i],b[i]});
ma[b[i]].push_back({t[i],a[i]});
}
for(int i=0;i<n;i++)
{
if(!vis[i]){
long long bv=vertex;
long long bd=dist;
vertex=-1;
dist=1e18;
dfs_down(i);
dfs_up(i);
if(bv!=-1)
{
ma[bv].push_back({l,vertex});
ma[vertex].push_back({l,bv});
long long stp=vertex;
vertex=-1;
dist=1e18;
dfs_down(stp);
fill();
dfs_up(stp);
}
}
}
cp=-1;
tp=1;
dfs_down(0);
fill();
dfs_up(0);
// cout<<"adj\n";
// for(int i=0;i<n;i++)
// {
// cout<<"For "<<i<<' ';
// for(auto [j,p]:ma[i]){
// cout<<p<<' ';
// }
// cout<<endl;
// cout<<"a\n";
// }
return cp;
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:88:14: warning: unused variable 'bd' [-Wunused-variable]
88 | long long bd=dist;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
15196 KB |
Output is correct |
2 |
Correct |
39 ms |
14928 KB |
Output is correct |
3 |
Correct |
29 ms |
13912 KB |
Output is correct |
4 |
Correct |
7 ms |
8028 KB |
Output is correct |
5 |
Correct |
6 ms |
7772 KB |
Output is correct |
6 |
Correct |
11 ms |
9052 KB |
Output is correct |
7 |
Correct |
1 ms |
7000 KB |
Output is correct |
8 |
Correct |
23 ms |
10588 KB |
Output is correct |
9 |
Correct |
28 ms |
12812 KB |
Output is correct |
10 |
Correct |
2 ms |
7004 KB |
Output is correct |
11 |
Correct |
37 ms |
13396 KB |
Output is correct |
12 |
Correct |
44 ms |
14428 KB |
Output is correct |
13 |
Correct |
1 ms |
7004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7004 KB |
Output is correct |
2 |
Correct |
1 ms |
7012 KB |
Output is correct |
3 |
Correct |
1 ms |
7004 KB |
Output is correct |
4 |
Correct |
2 ms |
7004 KB |
Output is correct |
5 |
Correct |
1 ms |
7004 KB |
Output is correct |
6 |
Correct |
2 ms |
7000 KB |
Output is correct |
7 |
Correct |
1 ms |
7004 KB |
Output is correct |
8 |
Correct |
1 ms |
7004 KB |
Output is correct |
9 |
Correct |
1 ms |
7256 KB |
Output is correct |
10 |
Correct |
1 ms |
7004 KB |
Output is correct |
11 |
Correct |
1 ms |
7004 KB |
Output is correct |
12 |
Correct |
1 ms |
7004 KB |
Output is correct |
13 |
Correct |
1 ms |
7004 KB |
Output is correct |
14 |
Correct |
1 ms |
7004 KB |
Output is correct |
15 |
Correct |
1 ms |
7004 KB |
Output is correct |
16 |
Correct |
2 ms |
7004 KB |
Output is correct |
17 |
Correct |
1 ms |
7004 KB |
Output is correct |
18 |
Correct |
1 ms |
7004 KB |
Output is correct |
19 |
Correct |
1 ms |
7004 KB |
Output is correct |
20 |
Correct |
1 ms |
7004 KB |
Output is correct |
21 |
Correct |
1 ms |
7004 KB |
Output is correct |
22 |
Correct |
1 ms |
7000 KB |
Output is correct |
23 |
Correct |
1 ms |
7000 KB |
Output is correct |
24 |
Correct |
1 ms |
7004 KB |
Output is correct |
25 |
Correct |
1 ms |
7004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
15196 KB |
Output is correct |
2 |
Correct |
39 ms |
14928 KB |
Output is correct |
3 |
Correct |
29 ms |
13912 KB |
Output is correct |
4 |
Correct |
7 ms |
8028 KB |
Output is correct |
5 |
Correct |
6 ms |
7772 KB |
Output is correct |
6 |
Correct |
11 ms |
9052 KB |
Output is correct |
7 |
Correct |
1 ms |
7000 KB |
Output is correct |
8 |
Correct |
23 ms |
10588 KB |
Output is correct |
9 |
Correct |
28 ms |
12812 KB |
Output is correct |
10 |
Correct |
2 ms |
7004 KB |
Output is correct |
11 |
Correct |
37 ms |
13396 KB |
Output is correct |
12 |
Correct |
44 ms |
14428 KB |
Output is correct |
13 |
Correct |
1 ms |
7004 KB |
Output is correct |
14 |
Correct |
1 ms |
7004 KB |
Output is correct |
15 |
Correct |
1 ms |
7012 KB |
Output is correct |
16 |
Correct |
1 ms |
7004 KB |
Output is correct |
17 |
Correct |
2 ms |
7004 KB |
Output is correct |
18 |
Correct |
1 ms |
7004 KB |
Output is correct |
19 |
Correct |
2 ms |
7000 KB |
Output is correct |
20 |
Correct |
1 ms |
7004 KB |
Output is correct |
21 |
Correct |
1 ms |
7004 KB |
Output is correct |
22 |
Correct |
1 ms |
7256 KB |
Output is correct |
23 |
Correct |
1 ms |
7004 KB |
Output is correct |
24 |
Correct |
1 ms |
7004 KB |
Output is correct |
25 |
Correct |
1 ms |
7004 KB |
Output is correct |
26 |
Correct |
1 ms |
7004 KB |
Output is correct |
27 |
Correct |
1 ms |
7004 KB |
Output is correct |
28 |
Correct |
1 ms |
7004 KB |
Output is correct |
29 |
Correct |
2 ms |
7004 KB |
Output is correct |
30 |
Correct |
1 ms |
7004 KB |
Output is correct |
31 |
Correct |
1 ms |
7004 KB |
Output is correct |
32 |
Correct |
1 ms |
7004 KB |
Output is correct |
33 |
Correct |
1 ms |
7004 KB |
Output is correct |
34 |
Correct |
1 ms |
7004 KB |
Output is correct |
35 |
Correct |
1 ms |
7000 KB |
Output is correct |
36 |
Correct |
1 ms |
7000 KB |
Output is correct |
37 |
Correct |
1 ms |
7004 KB |
Output is correct |
38 |
Correct |
1 ms |
7004 KB |
Output is correct |
39 |
Correct |
43 ms |
15436 KB |
Output is correct |
40 |
Correct |
40 ms |
15104 KB |
Output is correct |
41 |
Correct |
26 ms |
13916 KB |
Output is correct |
42 |
Correct |
6 ms |
8028 KB |
Output is correct |
43 |
Correct |
1 ms |
7004 KB |
Output is correct |
44 |
Correct |
1 ms |
7004 KB |
Output is correct |
45 |
Correct |
1 ms |
7004 KB |
Output is correct |
46 |
Correct |
1 ms |
7004 KB |
Output is correct |
47 |
Correct |
1 ms |
7004 KB |
Output is correct |
48 |
Correct |
1 ms |
7004 KB |
Output is correct |
49 |
Correct |
1 ms |
7004 KB |
Output is correct |
50 |
Correct |
1 ms |
7004 KB |
Output is correct |
51 |
Correct |
1 ms |
7004 KB |
Output is correct |
52 |
Correct |
1 ms |
7004 KB |
Output is correct |
53 |
Correct |
1 ms |
7004 KB |
Output is correct |
54 |
Correct |
1 ms |
7004 KB |
Output is correct |
55 |
Correct |
2 ms |
7004 KB |
Output is correct |
56 |
Correct |
1 ms |
7000 KB |
Output is correct |
57 |
Correct |
54 ms |
13080 KB |
Output is correct |
58 |
Correct |
53 ms |
13068 KB |
Output is correct |
59 |
Correct |
70 ms |
12624 KB |
Output is correct |
60 |
Correct |
54 ms |
12624 KB |
Output is correct |
61 |
Correct |
67 ms |
12788 KB |
Output is correct |
62 |
Correct |
52 ms |
12484 KB |
Output is correct |
63 |
Correct |
47 ms |
12124 KB |
Output is correct |
64 |
Correct |
46 ms |
12172 KB |
Output is correct |
65 |
Correct |
49 ms |
12124 KB |
Output is correct |
66 |
Correct |
47 ms |
12332 KB |
Output is correct |
67 |
Correct |
66 ms |
12880 KB |
Output is correct |
68 |
Correct |
53 ms |
12636 KB |
Output is correct |
69 |
Correct |
57 ms |
12636 KB |
Output is correct |
70 |
Correct |
59 ms |
12804 KB |
Output is correct |
71 |
Correct |
1 ms |
7000 KB |
Output is correct |
72 |
Correct |
2 ms |
7004 KB |
Output is correct |
73 |
Correct |
2 ms |
7004 KB |
Output is correct |
74 |
Correct |
2 ms |
7004 KB |
Output is correct |
75 |
Correct |
2 ms |
7256 KB |
Output is correct |
76 |
Correct |
2 ms |
7216 KB |
Output is correct |
77 |
Correct |
2 ms |
7000 KB |
Output is correct |
78 |
Correct |
2 ms |
7004 KB |
Output is correct |
79 |
Correct |
2 ms |
7004 KB |
Output is correct |
80 |
Correct |
56 ms |
12804 KB |
Output is correct |
81 |
Correct |
70 ms |
12808 KB |
Output is correct |
82 |
Correct |
52 ms |
12376 KB |
Output is correct |
83 |
Correct |
49 ms |
12368 KB |
Output is correct |
84 |
Correct |
2 ms |
7000 KB |
Output is correct |
85 |
Correct |
2 ms |
7004 KB |
Output is correct |
86 |
Correct |
2 ms |
7004 KB |
Output is correct |
87 |
Correct |
2 ms |
7004 KB |
Output is correct |
88 |
Correct |
2 ms |
7000 KB |
Output is correct |
89 |
Correct |
2 ms |
7004 KB |
Output is correct |
90 |
Correct |
2 ms |
7172 KB |
Output is correct |
91 |
Correct |
2 ms |
7004 KB |
Output is correct |
92 |
Correct |
2 ms |
7000 KB |
Output is correct |
93 |
Correct |
2 ms |
7004 KB |
Output is correct |
94 |
Correct |
1 ms |
7004 KB |
Output is correct |
95 |
Correct |
1 ms |
7004 KB |
Output is correct |
96 |
Correct |
1 ms |
7004 KB |
Output is correct |
97 |
Correct |
1 ms |
7004 KB |
Output is correct |
98 |
Correct |
1 ms |
7004 KB |
Output is correct |
99 |
Correct |
1 ms |
7004 KB |
Output is correct |
100 |
Correct |
1 ms |
7004 KB |
Output is correct |
101 |
Correct |
1 ms |
7004 KB |
Output is correct |
102 |
Correct |
1 ms |
7004 KB |
Output is correct |
103 |
Correct |
1 ms |
7000 KB |
Output is correct |
104 |
Correct |
6 ms |
7772 KB |
Output is correct |
105 |
Correct |
11 ms |
8848 KB |
Output is correct |
106 |
Correct |
1 ms |
7004 KB |
Output is correct |
107 |
Correct |
22 ms |
10808 KB |
Output is correct |
108 |
Correct |
36 ms |
12880 KB |
Output is correct |
109 |
Correct |
1 ms |
7004 KB |
Output is correct |
110 |
Correct |
38 ms |
13260 KB |
Output is correct |
111 |
Correct |
48 ms |
14380 KB |
Output is correct |
112 |
Correct |
1 ms |
7004 KB |
Output is correct |
113 |
Correct |
88 ms |
20112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1064 ms |
9436 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7004 KB |
Output is correct |
2 |
Correct |
1 ms |
7012 KB |
Output is correct |
3 |
Correct |
1 ms |
7004 KB |
Output is correct |
4 |
Correct |
2 ms |
7004 KB |
Output is correct |
5 |
Correct |
1 ms |
7004 KB |
Output is correct |
6 |
Correct |
2 ms |
7000 KB |
Output is correct |
7 |
Correct |
1 ms |
7004 KB |
Output is correct |
8 |
Correct |
1 ms |
7004 KB |
Output is correct |
9 |
Correct |
1 ms |
7256 KB |
Output is correct |
10 |
Correct |
1 ms |
7004 KB |
Output is correct |
11 |
Correct |
1 ms |
7004 KB |
Output is correct |
12 |
Correct |
1 ms |
7004 KB |
Output is correct |
13 |
Correct |
1 ms |
7004 KB |
Output is correct |
14 |
Correct |
1 ms |
7004 KB |
Output is correct |
15 |
Correct |
1 ms |
7004 KB |
Output is correct |
16 |
Correct |
2 ms |
7004 KB |
Output is correct |
17 |
Correct |
1 ms |
7004 KB |
Output is correct |
18 |
Correct |
1 ms |
7004 KB |
Output is correct |
19 |
Correct |
1 ms |
7004 KB |
Output is correct |
20 |
Correct |
1 ms |
7004 KB |
Output is correct |
21 |
Correct |
1 ms |
7004 KB |
Output is correct |
22 |
Correct |
1 ms |
7000 KB |
Output is correct |
23 |
Correct |
1 ms |
7000 KB |
Output is correct |
24 |
Correct |
1 ms |
7004 KB |
Output is correct |
25 |
Correct |
1 ms |
7004 KB |
Output is correct |
26 |
Correct |
3 ms |
7004 KB |
Output is correct |
27 |
Correct |
8 ms |
7028 KB |
Output is correct |
28 |
Correct |
19 ms |
7188 KB |
Output is correct |
29 |
Correct |
3 ms |
7004 KB |
Output is correct |
30 |
Correct |
8 ms |
7000 KB |
Output is correct |
31 |
Correct |
16 ms |
7196 KB |
Output is correct |
32 |
Correct |
3 ms |
7004 KB |
Output is correct |
33 |
Incorrect |
7 ms |
7140 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
15196 KB |
Output is correct |
2 |
Correct |
39 ms |
14928 KB |
Output is correct |
3 |
Correct |
29 ms |
13912 KB |
Output is correct |
4 |
Correct |
7 ms |
8028 KB |
Output is correct |
5 |
Correct |
6 ms |
7772 KB |
Output is correct |
6 |
Correct |
11 ms |
9052 KB |
Output is correct |
7 |
Correct |
1 ms |
7000 KB |
Output is correct |
8 |
Correct |
23 ms |
10588 KB |
Output is correct |
9 |
Correct |
28 ms |
12812 KB |
Output is correct |
10 |
Correct |
2 ms |
7004 KB |
Output is correct |
11 |
Correct |
37 ms |
13396 KB |
Output is correct |
12 |
Correct |
44 ms |
14428 KB |
Output is correct |
13 |
Correct |
1 ms |
7004 KB |
Output is correct |
14 |
Correct |
1 ms |
7004 KB |
Output is correct |
15 |
Correct |
1 ms |
7012 KB |
Output is correct |
16 |
Correct |
1 ms |
7004 KB |
Output is correct |
17 |
Correct |
2 ms |
7004 KB |
Output is correct |
18 |
Correct |
1 ms |
7004 KB |
Output is correct |
19 |
Correct |
2 ms |
7000 KB |
Output is correct |
20 |
Correct |
1 ms |
7004 KB |
Output is correct |
21 |
Correct |
1 ms |
7004 KB |
Output is correct |
22 |
Correct |
1 ms |
7256 KB |
Output is correct |
23 |
Correct |
1 ms |
7004 KB |
Output is correct |
24 |
Correct |
1 ms |
7004 KB |
Output is correct |
25 |
Correct |
1 ms |
7004 KB |
Output is correct |
26 |
Correct |
1 ms |
7004 KB |
Output is correct |
27 |
Correct |
1 ms |
7004 KB |
Output is correct |
28 |
Correct |
1 ms |
7004 KB |
Output is correct |
29 |
Correct |
2 ms |
7004 KB |
Output is correct |
30 |
Correct |
1 ms |
7004 KB |
Output is correct |
31 |
Correct |
1 ms |
7004 KB |
Output is correct |
32 |
Correct |
1 ms |
7004 KB |
Output is correct |
33 |
Correct |
1 ms |
7004 KB |
Output is correct |
34 |
Correct |
1 ms |
7004 KB |
Output is correct |
35 |
Correct |
1 ms |
7000 KB |
Output is correct |
36 |
Correct |
1 ms |
7000 KB |
Output is correct |
37 |
Correct |
1 ms |
7004 KB |
Output is correct |
38 |
Correct |
1 ms |
7004 KB |
Output is correct |
39 |
Correct |
43 ms |
15436 KB |
Output is correct |
40 |
Correct |
40 ms |
15104 KB |
Output is correct |
41 |
Correct |
26 ms |
13916 KB |
Output is correct |
42 |
Correct |
6 ms |
8028 KB |
Output is correct |
43 |
Correct |
1 ms |
7004 KB |
Output is correct |
44 |
Correct |
1 ms |
7004 KB |
Output is correct |
45 |
Correct |
1 ms |
7004 KB |
Output is correct |
46 |
Correct |
1 ms |
7004 KB |
Output is correct |
47 |
Correct |
1 ms |
7004 KB |
Output is correct |
48 |
Correct |
1 ms |
7004 KB |
Output is correct |
49 |
Correct |
1 ms |
7004 KB |
Output is correct |
50 |
Correct |
1 ms |
7004 KB |
Output is correct |
51 |
Correct |
1 ms |
7004 KB |
Output is correct |
52 |
Correct |
1 ms |
7004 KB |
Output is correct |
53 |
Correct |
1 ms |
7004 KB |
Output is correct |
54 |
Correct |
1 ms |
7004 KB |
Output is correct |
55 |
Correct |
2 ms |
7004 KB |
Output is correct |
56 |
Correct |
1 ms |
7000 KB |
Output is correct |
57 |
Correct |
54 ms |
13080 KB |
Output is correct |
58 |
Correct |
53 ms |
13068 KB |
Output is correct |
59 |
Correct |
70 ms |
12624 KB |
Output is correct |
60 |
Correct |
54 ms |
12624 KB |
Output is correct |
61 |
Correct |
67 ms |
12788 KB |
Output is correct |
62 |
Correct |
52 ms |
12484 KB |
Output is correct |
63 |
Correct |
47 ms |
12124 KB |
Output is correct |
64 |
Correct |
46 ms |
12172 KB |
Output is correct |
65 |
Correct |
49 ms |
12124 KB |
Output is correct |
66 |
Correct |
47 ms |
12332 KB |
Output is correct |
67 |
Correct |
66 ms |
12880 KB |
Output is correct |
68 |
Correct |
53 ms |
12636 KB |
Output is correct |
69 |
Correct |
57 ms |
12636 KB |
Output is correct |
70 |
Correct |
59 ms |
12804 KB |
Output is correct |
71 |
Correct |
1 ms |
7000 KB |
Output is correct |
72 |
Correct |
2 ms |
7004 KB |
Output is correct |
73 |
Correct |
2 ms |
7004 KB |
Output is correct |
74 |
Correct |
2 ms |
7004 KB |
Output is correct |
75 |
Correct |
2 ms |
7256 KB |
Output is correct |
76 |
Correct |
2 ms |
7216 KB |
Output is correct |
77 |
Correct |
2 ms |
7000 KB |
Output is correct |
78 |
Correct |
2 ms |
7004 KB |
Output is correct |
79 |
Correct |
2 ms |
7004 KB |
Output is correct |
80 |
Correct |
56 ms |
12804 KB |
Output is correct |
81 |
Correct |
70 ms |
12808 KB |
Output is correct |
82 |
Correct |
52 ms |
12376 KB |
Output is correct |
83 |
Correct |
49 ms |
12368 KB |
Output is correct |
84 |
Correct |
2 ms |
7000 KB |
Output is correct |
85 |
Correct |
2 ms |
7004 KB |
Output is correct |
86 |
Correct |
2 ms |
7004 KB |
Output is correct |
87 |
Correct |
2 ms |
7004 KB |
Output is correct |
88 |
Correct |
2 ms |
7000 KB |
Output is correct |
89 |
Correct |
2 ms |
7004 KB |
Output is correct |
90 |
Correct |
2 ms |
7172 KB |
Output is correct |
91 |
Correct |
2 ms |
7004 KB |
Output is correct |
92 |
Correct |
2 ms |
7000 KB |
Output is correct |
93 |
Correct |
2 ms |
7004 KB |
Output is correct |
94 |
Correct |
1 ms |
7004 KB |
Output is correct |
95 |
Correct |
1 ms |
7004 KB |
Output is correct |
96 |
Correct |
1 ms |
7004 KB |
Output is correct |
97 |
Correct |
1 ms |
7004 KB |
Output is correct |
98 |
Correct |
1 ms |
7004 KB |
Output is correct |
99 |
Correct |
1 ms |
7004 KB |
Output is correct |
100 |
Correct |
1 ms |
7004 KB |
Output is correct |
101 |
Correct |
1 ms |
7004 KB |
Output is correct |
102 |
Correct |
1 ms |
7004 KB |
Output is correct |
103 |
Correct |
1 ms |
7000 KB |
Output is correct |
104 |
Correct |
6 ms |
7772 KB |
Output is correct |
105 |
Correct |
11 ms |
8848 KB |
Output is correct |
106 |
Correct |
1 ms |
7004 KB |
Output is correct |
107 |
Correct |
22 ms |
10808 KB |
Output is correct |
108 |
Correct |
36 ms |
12880 KB |
Output is correct |
109 |
Correct |
1 ms |
7004 KB |
Output is correct |
110 |
Correct |
38 ms |
13260 KB |
Output is correct |
111 |
Correct |
48 ms |
14380 KB |
Output is correct |
112 |
Correct |
1 ms |
7004 KB |
Output is correct |
113 |
Correct |
88 ms |
20112 KB |
Output is correct |
114 |
Execution timed out |
1064 ms |
9436 KB |
Time limit exceeded |
115 |
Halted |
0 ms |
0 KB |
- |