#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;
vector<int>v;
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);
v.pb(d.F);
if(mx1<mx2)swap(mx1,mx2);
}
sort(all(v));
reverse(all(v));
int b=N-M-1;
if(b>1){
ret=max(ret,2*L);
ret=max(ret,v[0]+v[2]+l+l);
}
ret=max(ret,mx1+mx2+(l*(b>0)));
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
15992 KB |
Output is correct |
2 |
Correct |
90 ms |
15940 KB |
Output is correct |
3 |
Correct |
46 ms |
11384 KB |
Output is correct |
4 |
Correct |
12 ms |
4608 KB |
Output is correct |
5 |
Correct |
10 ms |
3712 KB |
Output is correct |
6 |
Correct |
18 ms |
5524 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
31 ms |
7032 KB |
Output is correct |
9 |
Correct |
40 ms |
9080 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
59 ms |
10744 KB |
Output is correct |
12 |
Correct |
76 ms |
13304 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
15992 KB |
Output is correct |
2 |
Correct |
90 ms |
15940 KB |
Output is correct |
3 |
Correct |
46 ms |
11384 KB |
Output is correct |
4 |
Correct |
12 ms |
4608 KB |
Output is correct |
5 |
Correct |
10 ms |
3712 KB |
Output is correct |
6 |
Correct |
18 ms |
5524 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
31 ms |
7032 KB |
Output is correct |
9 |
Correct |
40 ms |
9080 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
59 ms |
10744 KB |
Output is correct |
12 |
Correct |
76 ms |
13304 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
4 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 |
3 ms |
2688 KB |
Output is correct |
20 |
Correct |
3 ms |
2688 KB |
Output is correct |
21 |
Correct |
3 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2816 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
3 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
3 ms |
2688 KB |
Output is correct |
28 |
Correct |
3 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 |
2704 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 |
3 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
15992 KB |
Output is correct |
2 |
Correct |
90 ms |
15940 KB |
Output is correct |
3 |
Correct |
46 ms |
11384 KB |
Output is correct |
4 |
Correct |
12 ms |
4608 KB |
Output is correct |
5 |
Correct |
10 ms |
3712 KB |
Output is correct |
6 |
Correct |
18 ms |
5524 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
31 ms |
7032 KB |
Output is correct |
9 |
Correct |
40 ms |
9080 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
59 ms |
10744 KB |
Output is correct |
12 |
Correct |
76 ms |
13304 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
4 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 |
3 ms |
2688 KB |
Output is correct |
20 |
Correct |
3 ms |
2688 KB |
Output is correct |
21 |
Correct |
3 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2816 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
3 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
3 ms |
2688 KB |
Output is correct |
28 |
Correct |
3 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 |
2704 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 |
3 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
39 |
Correct |
80 ms |
16012 KB |
Output is correct |
40 |
Correct |
74 ms |
15992 KB |
Output is correct |
41 |
Correct |
61 ms |
11384 KB |
Output is correct |
42 |
Correct |
11 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 |
3 ms |
2688 KB |
Output is correct |
46 |
Correct |
4 ms |
2688 KB |
Output is correct |
47 |
Correct |
4 ms |
2688 KB |
Output is correct |
48 |
Correct |
4 ms |
2688 KB |
Output is correct |
49 |
Correct |
4 ms |
2688 KB |
Output is correct |
50 |
Correct |
4 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 |
77 ms |
8696 KB |
Output is correct |
58 |
Correct |
77 ms |
8696 KB |
Output is correct |
59 |
Correct |
88 ms |
8696 KB |
Output is correct |
60 |
Correct |
67 ms |
8696 KB |
Output is correct |
61 |
Correct |
81 ms |
8568 KB |
Output is correct |
62 |
Correct |
71 ms |
8568 KB |
Output is correct |
63 |
Correct |
76 ms |
8528 KB |
Output is correct |
64 |
Correct |
73 ms |
8316 KB |
Output is correct |
65 |
Correct |
77 ms |
8444 KB |
Output is correct |
66 |
Correct |
75 ms |
8440 KB |
Output is correct |
67 |
Correct |
88 ms |
8864 KB |
Output is correct |
68 |
Correct |
64 ms |
8696 KB |
Output is correct |
69 |
Correct |
101 ms |
8696 KB |
Output is correct |
70 |
Correct |
75 ms |
8700 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 |
2944 KB |
Output is correct |
74 |
Correct |
5 ms |
2816 KB |
Output is correct |
75 |
Correct |
5 ms |
2944 KB |
Output is correct |
76 |
Correct |
7 ms |
2816 KB |
Output is correct |
77 |
Correct |
5 ms |
2816 KB |
Output is correct |
78 |
Correct |
5 ms |
2944 KB |
Output is correct |
79 |
Correct |
5 ms |
2944 KB |
Output is correct |
80 |
Correct |
78 ms |
8696 KB |
Output is correct |
81 |
Correct |
85 ms |
8696 KB |
Output is correct |
82 |
Correct |
102 ms |
8500 KB |
Output is correct |
83 |
Correct |
90 ms |
8636 KB |
Output is correct |
84 |
Correct |
5 ms |
2816 KB |
Output is correct |
85 |
Correct |
5 ms |
2816 KB |
Output is correct |
86 |
Correct |
5 ms |
2816 KB |
Output is correct |
87 |
Correct |
8 ms |
2816 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 |
2816 KB |
Output is correct |
91 |
Correct |
6 ms |
2944 KB |
Output is correct |
92 |
Correct |
6 ms |
2816 KB |
Output is correct |
93 |
Correct |
5 ms |
2816 KB |
Output is correct |
94 |
Correct |
4 ms |
2688 KB |
Output is correct |
95 |
Correct |
5 ms |
2688 KB |
Output is correct |
96 |
Correct |
3 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 |
3 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 |
4 ms |
2688 KB |
Output is correct |
104 |
Correct |
11 ms |
3712 KB |
Output is correct |
105 |
Correct |
18 ms |
5632 KB |
Output is correct |
106 |
Correct |
4 ms |
2776 KB |
Output is correct |
107 |
Correct |
30 ms |
7032 KB |
Output is correct |
108 |
Correct |
59 ms |
9080 KB |
Output is correct |
109 |
Correct |
5 ms |
2816 KB |
Output is correct |
110 |
Correct |
62 ms |
10744 KB |
Output is correct |
111 |
Correct |
65 ms |
13304 KB |
Output is correct |
112 |
Correct |
4 ms |
2816 KB |
Output is correct |
113 |
Correct |
121 ms |
17276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
6264 KB |
Output is correct |
2 |
Incorrect |
30 ms |
6264 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
15992 KB |
Output is correct |
2 |
Correct |
90 ms |
15940 KB |
Output is correct |
3 |
Correct |
46 ms |
11384 KB |
Output is correct |
4 |
Correct |
12 ms |
4608 KB |
Output is correct |
5 |
Correct |
10 ms |
3712 KB |
Output is correct |
6 |
Correct |
18 ms |
5524 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
31 ms |
7032 KB |
Output is correct |
9 |
Correct |
40 ms |
9080 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
59 ms |
10744 KB |
Output is correct |
12 |
Correct |
76 ms |
13304 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 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 |
2816 KB |
Output is correct |
18 |
Correct |
5 ms |
2816 KB |
Output is correct |
19 |
Correct |
5 ms |
2816 KB |
Output is correct |
20 |
Incorrect |
4 ms |
2816 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
15992 KB |
Output is correct |
2 |
Correct |
90 ms |
15940 KB |
Output is correct |
3 |
Correct |
46 ms |
11384 KB |
Output is correct |
4 |
Correct |
12 ms |
4608 KB |
Output is correct |
5 |
Correct |
10 ms |
3712 KB |
Output is correct |
6 |
Correct |
18 ms |
5524 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
31 ms |
7032 KB |
Output is correct |
9 |
Correct |
40 ms |
9080 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
59 ms |
10744 KB |
Output is correct |
12 |
Correct |
76 ms |
13304 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
4 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 |
3 ms |
2688 KB |
Output is correct |
20 |
Correct |
3 ms |
2688 KB |
Output is correct |
21 |
Correct |
3 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2816 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
3 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
3 ms |
2688 KB |
Output is correct |
28 |
Correct |
3 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 |
2704 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 |
3 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
39 |
Correct |
80 ms |
16012 KB |
Output is correct |
40 |
Correct |
74 ms |
15992 KB |
Output is correct |
41 |
Correct |
61 ms |
11384 KB |
Output is correct |
42 |
Correct |
11 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 |
3 ms |
2688 KB |
Output is correct |
46 |
Correct |
4 ms |
2688 KB |
Output is correct |
47 |
Correct |
4 ms |
2688 KB |
Output is correct |
48 |
Correct |
4 ms |
2688 KB |
Output is correct |
49 |
Correct |
4 ms |
2688 KB |
Output is correct |
50 |
Correct |
4 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 |
77 ms |
8696 KB |
Output is correct |
58 |
Correct |
77 ms |
8696 KB |
Output is correct |
59 |
Correct |
88 ms |
8696 KB |
Output is correct |
60 |
Correct |
67 ms |
8696 KB |
Output is correct |
61 |
Correct |
81 ms |
8568 KB |
Output is correct |
62 |
Correct |
71 ms |
8568 KB |
Output is correct |
63 |
Correct |
76 ms |
8528 KB |
Output is correct |
64 |
Correct |
73 ms |
8316 KB |
Output is correct |
65 |
Correct |
77 ms |
8444 KB |
Output is correct |
66 |
Correct |
75 ms |
8440 KB |
Output is correct |
67 |
Correct |
88 ms |
8864 KB |
Output is correct |
68 |
Correct |
64 ms |
8696 KB |
Output is correct |
69 |
Correct |
101 ms |
8696 KB |
Output is correct |
70 |
Correct |
75 ms |
8700 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 |
2944 KB |
Output is correct |
74 |
Correct |
5 ms |
2816 KB |
Output is correct |
75 |
Correct |
5 ms |
2944 KB |
Output is correct |
76 |
Correct |
7 ms |
2816 KB |
Output is correct |
77 |
Correct |
5 ms |
2816 KB |
Output is correct |
78 |
Correct |
5 ms |
2944 KB |
Output is correct |
79 |
Correct |
5 ms |
2944 KB |
Output is correct |
80 |
Correct |
78 ms |
8696 KB |
Output is correct |
81 |
Correct |
85 ms |
8696 KB |
Output is correct |
82 |
Correct |
102 ms |
8500 KB |
Output is correct |
83 |
Correct |
90 ms |
8636 KB |
Output is correct |
84 |
Correct |
5 ms |
2816 KB |
Output is correct |
85 |
Correct |
5 ms |
2816 KB |
Output is correct |
86 |
Correct |
5 ms |
2816 KB |
Output is correct |
87 |
Correct |
8 ms |
2816 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 |
2816 KB |
Output is correct |
91 |
Correct |
6 ms |
2944 KB |
Output is correct |
92 |
Correct |
6 ms |
2816 KB |
Output is correct |
93 |
Correct |
5 ms |
2816 KB |
Output is correct |
94 |
Correct |
4 ms |
2688 KB |
Output is correct |
95 |
Correct |
5 ms |
2688 KB |
Output is correct |
96 |
Correct |
3 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 |
3 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 |
4 ms |
2688 KB |
Output is correct |
104 |
Correct |
11 ms |
3712 KB |
Output is correct |
105 |
Correct |
18 ms |
5632 KB |
Output is correct |
106 |
Correct |
4 ms |
2776 KB |
Output is correct |
107 |
Correct |
30 ms |
7032 KB |
Output is correct |
108 |
Correct |
59 ms |
9080 KB |
Output is correct |
109 |
Correct |
5 ms |
2816 KB |
Output is correct |
110 |
Correct |
62 ms |
10744 KB |
Output is correct |
111 |
Correct |
65 ms |
13304 KB |
Output is correct |
112 |
Correct |
4 ms |
2816 KB |
Output is correct |
113 |
Correct |
121 ms |
17276 KB |
Output is correct |
114 |
Correct |
29 ms |
6264 KB |
Output is correct |
115 |
Incorrect |
30 ms |
6264 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |