#include <bits/stdc++.h>
#include "dreaming.h"
#define F first
#define S second
#define P push
#define pb push_back
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define W while
#define R return
#define C continue
#define SI size()
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define SF(x) scanf("%I64d",&x)
#define SF2(x,y) scanf("%I64d%I64d",&x,&y)
#define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o)
#define all(v) v.begin(),v.end()
using namespace std;
const long long INF = 1e9;
const int MX=100005;
int n,m,l,dis[MX],go[MX];
vector<pii> adj[MX];
bool vis[MX];
pii DFS(int ver,int par,bool b){
vis[ver]=1;
pii ret;
ret={0,ver};
pii p;
for(auto i : adj[ver]){
if(i.F==par)C;
if(b)dis[i.F]=dis[ver]+i.S;
p=DFS(i.F,ver,b);
p.F+=i.S;
if(p.F>=ret.F){
ret.F=p.F;
ret.S=p.S;
}
}
// cout<<ver<<" "<<ret.F<<" "<<ret.S<<endl;
if(b)go[ver]=ret.F;
R ret;
}
pii dfs(int ver,int dia,int par){
if(dis[ver]+go[ver]!=dia)R {0,INF};
pii ret={dis[ver],go[ver]};
// cout<<ver<<" "<<dis[ver]<<" "<<go[ver]<<endl;
for(auto i : adj[ver]){
if(par==i.F)C;
pii p=dfs(i.F,dia,ver);
if(abs(p.F-p.S)<abs(ret.F-ret.S)){
ret=p;
}
}
R ret;
}
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++){
adj[A[i]].pb({B[i],T[i]});
adj[B[i]].pb({A[i],T[i]});
}
int mx1=0,mx2=0;
int ret=0;
for(int i=0;i<n;i++){
if(vis[i])C;
pii p=DFS(i,-1,0);
int x=p.S;
p=DFS(p.S,-1,1);
pii d=dfs(x,p.F,-1);
ret=max(ret,p.F);
// cout<<i<<" "<<p.F<<" "<<d.F<<" "<<d.S<<endl;
if(d.F<d.S)swap(d.F,d.S);
mx2=max(mx2,d.F);
if(mx1<mx2)swap(mx1,mx2);
}
ret=max(ret,mx1+mx2+l);
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
15964 KB |
Output is correct |
2 |
Correct |
87 ms |
15992 KB |
Output is correct |
3 |
Correct |
50 ms |
11384 KB |
Output is correct |
4 |
Correct |
12 ms |
4608 KB |
Output is correct |
5 |
Correct |
10 ms |
3756 KB |
Output is correct |
6 |
Correct |
18 ms |
5632 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
33 ms |
7040 KB |
Output is correct |
9 |
Correct |
41 ms |
9080 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
69 ms |
10716 KB |
Output is correct |
12 |
Correct |
86 ms |
13308 KB |
Output is correct |
13 |
Correct |
4 ms |
2812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
15964 KB |
Output is correct |
2 |
Correct |
87 ms |
15992 KB |
Output is correct |
3 |
Correct |
50 ms |
11384 KB |
Output is correct |
4 |
Correct |
12 ms |
4608 KB |
Output is correct |
5 |
Correct |
10 ms |
3756 KB |
Output is correct |
6 |
Correct |
18 ms |
5632 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
33 ms |
7040 KB |
Output is correct |
9 |
Correct |
41 ms |
9080 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
69 ms |
10716 KB |
Output is correct |
12 |
Correct |
86 ms |
13308 KB |
Output is correct |
13 |
Correct |
4 ms |
2812 KB |
Output is correct |
14 |
Correct |
0 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2688 KB |
Output is correct |
16 |
Correct |
4 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2688 KB |
Output is correct |
18 |
Correct |
4 ms |
2688 KB |
Output is correct |
19 |
Correct |
4 ms |
2660 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
3 ms |
2688 KB |
Output is correct |
22 |
Correct |
3 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
4 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
4 ms |
2688 KB |
Output is correct |
31 |
Correct |
4 ms |
2688 KB |
Output is correct |
32 |
Correct |
4 ms |
2688 KB |
Output is correct |
33 |
Correct |
4 ms |
2688 KB |
Output is correct |
34 |
Correct |
4 ms |
2688 KB |
Output is correct |
35 |
Correct |
4 ms |
2688 KB |
Output is correct |
36 |
Correct |
4 ms |
2688 KB |
Output is correct |
37 |
Correct |
3 ms |
2716 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
15964 KB |
Output is correct |
2 |
Correct |
87 ms |
15992 KB |
Output is correct |
3 |
Correct |
50 ms |
11384 KB |
Output is correct |
4 |
Correct |
12 ms |
4608 KB |
Output is correct |
5 |
Correct |
10 ms |
3756 KB |
Output is correct |
6 |
Correct |
18 ms |
5632 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
33 ms |
7040 KB |
Output is correct |
9 |
Correct |
41 ms |
9080 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
69 ms |
10716 KB |
Output is correct |
12 |
Correct |
86 ms |
13308 KB |
Output is correct |
13 |
Correct |
4 ms |
2812 KB |
Output is correct |
14 |
Correct |
0 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2688 KB |
Output is correct |
16 |
Correct |
4 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2688 KB |
Output is correct |
18 |
Correct |
4 ms |
2688 KB |
Output is correct |
19 |
Correct |
4 ms |
2660 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
3 ms |
2688 KB |
Output is correct |
22 |
Correct |
3 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
4 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
4 ms |
2688 KB |
Output is correct |
31 |
Correct |
4 ms |
2688 KB |
Output is correct |
32 |
Correct |
4 ms |
2688 KB |
Output is correct |
33 |
Correct |
4 ms |
2688 KB |
Output is correct |
34 |
Correct |
4 ms |
2688 KB |
Output is correct |
35 |
Correct |
4 ms |
2688 KB |
Output is correct |
36 |
Correct |
4 ms |
2688 KB |
Output is correct |
37 |
Correct |
3 ms |
2716 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
39 |
Correct |
85 ms |
16036 KB |
Output is correct |
40 |
Correct |
82 ms |
15908 KB |
Output is correct |
41 |
Correct |
50 ms |
11384 KB |
Output is correct |
42 |
Correct |
12 ms |
4608 KB |
Output is correct |
43 |
Correct |
4 ms |
2688 KB |
Output is correct |
44 |
Correct |
4 ms |
2688 KB |
Output is correct |
45 |
Correct |
4 ms |
2688 KB |
Output is correct |
46 |
Correct |
4 ms |
2660 KB |
Output is correct |
47 |
Correct |
3 ms |
2688 KB |
Output is correct |
48 |
Correct |
3 ms |
2688 KB |
Output is correct |
49 |
Correct |
3 ms |
2688 KB |
Output is correct |
50 |
Correct |
3 ms |
2688 KB |
Output is correct |
51 |
Correct |
4 ms |
2688 KB |
Output is correct |
52 |
Correct |
4 ms |
2688 KB |
Output is correct |
53 |
Correct |
4 ms |
2688 KB |
Output is correct |
54 |
Correct |
4 ms |
2688 KB |
Output is correct |
55 |
Correct |
4 ms |
2688 KB |
Output is correct |
56 |
Correct |
4 ms |
2688 KB |
Output is correct |
57 |
Correct |
78 ms |
8696 KB |
Output is correct |
58 |
Correct |
101 ms |
8824 KB |
Output is correct |
59 |
Correct |
74 ms |
8696 KB |
Output is correct |
60 |
Correct |
86 ms |
8744 KB |
Output is correct |
61 |
Correct |
81 ms |
8696 KB |
Output is correct |
62 |
Correct |
80 ms |
8568 KB |
Output is correct |
63 |
Correct |
63 ms |
8440 KB |
Output is correct |
64 |
Correct |
82 ms |
8384 KB |
Output is correct |
65 |
Correct |
93 ms |
8440 KB |
Output is correct |
66 |
Correct |
86 ms |
8440 KB |
Output is correct |
67 |
Correct |
72 ms |
8696 KB |
Output is correct |
68 |
Correct |
92 ms |
8720 KB |
Output is correct |
69 |
Correct |
84 ms |
8696 KB |
Output is correct |
70 |
Correct |
79 ms |
8696 KB |
Output is correct |
71 |
Correct |
4 ms |
2688 KB |
Output is correct |
72 |
Correct |
5 ms |
2944 KB |
Output is correct |
73 |
Correct |
5 ms |
2816 KB |
Output is correct |
74 |
Correct |
5 ms |
2944 KB |
Output is correct |
75 |
Correct |
5 ms |
2944 KB |
Output is correct |
76 |
Correct |
5 ms |
2944 KB |
Output is correct |
77 |
Correct |
5 ms |
2916 KB |
Output is correct |
78 |
Correct |
5 ms |
2816 KB |
Output is correct |
79 |
Correct |
5 ms |
2944 KB |
Output is correct |
80 |
Correct |
85 ms |
8568 KB |
Output is correct |
81 |
Correct |
69 ms |
8696 KB |
Output is correct |
82 |
Correct |
73 ms |
8568 KB |
Output is correct |
83 |
Correct |
77 ms |
8568 KB |
Output is correct |
84 |
Correct |
5 ms |
2816 KB |
Output is correct |
85 |
Correct |
4 ms |
2816 KB |
Output is correct |
86 |
Correct |
4 ms |
2816 KB |
Output is correct |
87 |
Correct |
5 ms |
2944 KB |
Output is correct |
88 |
Correct |
5 ms |
2816 KB |
Output is correct |
89 |
Correct |
5 ms |
2816 KB |
Output is correct |
90 |
Correct |
5 ms |
2808 KB |
Output is correct |
91 |
Correct |
5 ms |
2944 KB |
Output is correct |
92 |
Correct |
5 ms |
2816 KB |
Output is correct |
93 |
Correct |
5 ms |
2816 KB |
Output is correct |
94 |
Correct |
3 ms |
2688 KB |
Output is correct |
95 |
Correct |
4 ms |
2688 KB |
Output is correct |
96 |
Correct |
4 ms |
2688 KB |
Output is correct |
97 |
Correct |
4 ms |
2688 KB |
Output is correct |
98 |
Correct |
4 ms |
2688 KB |
Output is correct |
99 |
Correct |
4 ms |
2688 KB |
Output is correct |
100 |
Correct |
3 ms |
2688 KB |
Output is correct |
101 |
Correct |
4 ms |
2688 KB |
Output is correct |
102 |
Correct |
3 ms |
2688 KB |
Output is correct |
103 |
Correct |
3 ms |
2688 KB |
Output is correct |
104 |
Correct |
10 ms |
3712 KB |
Output is correct |
105 |
Correct |
19 ms |
5760 KB |
Output is correct |
106 |
Correct |
4 ms |
2688 KB |
Output is correct |
107 |
Correct |
31 ms |
7040 KB |
Output is correct |
108 |
Correct |
43 ms |
9088 KB |
Output is correct |
109 |
Correct |
4 ms |
2816 KB |
Output is correct |
110 |
Correct |
55 ms |
10752 KB |
Output is correct |
111 |
Correct |
72 ms |
13304 KB |
Output is correct |
112 |
Correct |
4 ms |
2816 KB |
Output is correct |
113 |
Correct |
110 ms |
17188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
5760 KB |
Output is correct |
2 |
Incorrect |
28 ms |
6016 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
15964 KB |
Output is correct |
2 |
Correct |
87 ms |
15992 KB |
Output is correct |
3 |
Correct |
50 ms |
11384 KB |
Output is correct |
4 |
Correct |
12 ms |
4608 KB |
Output is correct |
5 |
Correct |
10 ms |
3756 KB |
Output is correct |
6 |
Correct |
18 ms |
5632 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
33 ms |
7040 KB |
Output is correct |
9 |
Correct |
41 ms |
9080 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
69 ms |
10716 KB |
Output is correct |
12 |
Correct |
86 ms |
13308 KB |
Output is correct |
13 |
Correct |
4 ms |
2812 KB |
Output is correct |
14 |
Correct |
4 ms |
2788 KB |
Output is correct |
15 |
Correct |
5 ms |
2816 KB |
Output is correct |
16 |
Correct |
5 ms |
2816 KB |
Output is correct |
17 |
Correct |
4 ms |
2688 KB |
Output is correct |
18 |
Correct |
4 ms |
2816 KB |
Output is correct |
19 |
Correct |
5 ms |
2816 KB |
Output is correct |
20 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
15964 KB |
Output is correct |
2 |
Correct |
87 ms |
15992 KB |
Output is correct |
3 |
Correct |
50 ms |
11384 KB |
Output is correct |
4 |
Correct |
12 ms |
4608 KB |
Output is correct |
5 |
Correct |
10 ms |
3756 KB |
Output is correct |
6 |
Correct |
18 ms |
5632 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
33 ms |
7040 KB |
Output is correct |
9 |
Correct |
41 ms |
9080 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
69 ms |
10716 KB |
Output is correct |
12 |
Correct |
86 ms |
13308 KB |
Output is correct |
13 |
Correct |
4 ms |
2812 KB |
Output is correct |
14 |
Correct |
0 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2688 KB |
Output is correct |
16 |
Correct |
4 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2688 KB |
Output is correct |
18 |
Correct |
4 ms |
2688 KB |
Output is correct |
19 |
Correct |
4 ms |
2660 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
3 ms |
2688 KB |
Output is correct |
22 |
Correct |
3 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
4 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
4 ms |
2688 KB |
Output is correct |
31 |
Correct |
4 ms |
2688 KB |
Output is correct |
32 |
Correct |
4 ms |
2688 KB |
Output is correct |
33 |
Correct |
4 ms |
2688 KB |
Output is correct |
34 |
Correct |
4 ms |
2688 KB |
Output is correct |
35 |
Correct |
4 ms |
2688 KB |
Output is correct |
36 |
Correct |
4 ms |
2688 KB |
Output is correct |
37 |
Correct |
3 ms |
2716 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
39 |
Correct |
85 ms |
16036 KB |
Output is correct |
40 |
Correct |
82 ms |
15908 KB |
Output is correct |
41 |
Correct |
50 ms |
11384 KB |
Output is correct |
42 |
Correct |
12 ms |
4608 KB |
Output is correct |
43 |
Correct |
4 ms |
2688 KB |
Output is correct |
44 |
Correct |
4 ms |
2688 KB |
Output is correct |
45 |
Correct |
4 ms |
2688 KB |
Output is correct |
46 |
Correct |
4 ms |
2660 KB |
Output is correct |
47 |
Correct |
3 ms |
2688 KB |
Output is correct |
48 |
Correct |
3 ms |
2688 KB |
Output is correct |
49 |
Correct |
3 ms |
2688 KB |
Output is correct |
50 |
Correct |
3 ms |
2688 KB |
Output is correct |
51 |
Correct |
4 ms |
2688 KB |
Output is correct |
52 |
Correct |
4 ms |
2688 KB |
Output is correct |
53 |
Correct |
4 ms |
2688 KB |
Output is correct |
54 |
Correct |
4 ms |
2688 KB |
Output is correct |
55 |
Correct |
4 ms |
2688 KB |
Output is correct |
56 |
Correct |
4 ms |
2688 KB |
Output is correct |
57 |
Correct |
78 ms |
8696 KB |
Output is correct |
58 |
Correct |
101 ms |
8824 KB |
Output is correct |
59 |
Correct |
74 ms |
8696 KB |
Output is correct |
60 |
Correct |
86 ms |
8744 KB |
Output is correct |
61 |
Correct |
81 ms |
8696 KB |
Output is correct |
62 |
Correct |
80 ms |
8568 KB |
Output is correct |
63 |
Correct |
63 ms |
8440 KB |
Output is correct |
64 |
Correct |
82 ms |
8384 KB |
Output is correct |
65 |
Correct |
93 ms |
8440 KB |
Output is correct |
66 |
Correct |
86 ms |
8440 KB |
Output is correct |
67 |
Correct |
72 ms |
8696 KB |
Output is correct |
68 |
Correct |
92 ms |
8720 KB |
Output is correct |
69 |
Correct |
84 ms |
8696 KB |
Output is correct |
70 |
Correct |
79 ms |
8696 KB |
Output is correct |
71 |
Correct |
4 ms |
2688 KB |
Output is correct |
72 |
Correct |
5 ms |
2944 KB |
Output is correct |
73 |
Correct |
5 ms |
2816 KB |
Output is correct |
74 |
Correct |
5 ms |
2944 KB |
Output is correct |
75 |
Correct |
5 ms |
2944 KB |
Output is correct |
76 |
Correct |
5 ms |
2944 KB |
Output is correct |
77 |
Correct |
5 ms |
2916 KB |
Output is correct |
78 |
Correct |
5 ms |
2816 KB |
Output is correct |
79 |
Correct |
5 ms |
2944 KB |
Output is correct |
80 |
Correct |
85 ms |
8568 KB |
Output is correct |
81 |
Correct |
69 ms |
8696 KB |
Output is correct |
82 |
Correct |
73 ms |
8568 KB |
Output is correct |
83 |
Correct |
77 ms |
8568 KB |
Output is correct |
84 |
Correct |
5 ms |
2816 KB |
Output is correct |
85 |
Correct |
4 ms |
2816 KB |
Output is correct |
86 |
Correct |
4 ms |
2816 KB |
Output is correct |
87 |
Correct |
5 ms |
2944 KB |
Output is correct |
88 |
Correct |
5 ms |
2816 KB |
Output is correct |
89 |
Correct |
5 ms |
2816 KB |
Output is correct |
90 |
Correct |
5 ms |
2808 KB |
Output is correct |
91 |
Correct |
5 ms |
2944 KB |
Output is correct |
92 |
Correct |
5 ms |
2816 KB |
Output is correct |
93 |
Correct |
5 ms |
2816 KB |
Output is correct |
94 |
Correct |
3 ms |
2688 KB |
Output is correct |
95 |
Correct |
4 ms |
2688 KB |
Output is correct |
96 |
Correct |
4 ms |
2688 KB |
Output is correct |
97 |
Correct |
4 ms |
2688 KB |
Output is correct |
98 |
Correct |
4 ms |
2688 KB |
Output is correct |
99 |
Correct |
4 ms |
2688 KB |
Output is correct |
100 |
Correct |
3 ms |
2688 KB |
Output is correct |
101 |
Correct |
4 ms |
2688 KB |
Output is correct |
102 |
Correct |
3 ms |
2688 KB |
Output is correct |
103 |
Correct |
3 ms |
2688 KB |
Output is correct |
104 |
Correct |
10 ms |
3712 KB |
Output is correct |
105 |
Correct |
19 ms |
5760 KB |
Output is correct |
106 |
Correct |
4 ms |
2688 KB |
Output is correct |
107 |
Correct |
31 ms |
7040 KB |
Output is correct |
108 |
Correct |
43 ms |
9088 KB |
Output is correct |
109 |
Correct |
4 ms |
2816 KB |
Output is correct |
110 |
Correct |
55 ms |
10752 KB |
Output is correct |
111 |
Correct |
72 ms |
13304 KB |
Output is correct |
112 |
Correct |
4 ms |
2816 KB |
Output is correct |
113 |
Correct |
110 ms |
17188 KB |
Output is correct |
114 |
Correct |
25 ms |
5760 KB |
Output is correct |
115 |
Incorrect |
28 ms |
6016 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |