#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
const int MAX=1e5+10;
const int INF=(1<<30);
vector<pair<int,int> > graph[MAX];
vector<int> radius;
int dist[MAX];
int vis[MAX];
int FindEnd(int start, int status)
{
queue<int> q;
int index,max_dist;
index=start;max_dist=0;
q.push(start);
vis[start]=status;
dist[start]=0;
while(!q.empty())
{
int curr=q.front();
q.pop();
for(auto neighbour:graph[curr])
{
int newidx=neighbour.first;
int cost=neighbour.second;
if(vis[newidx]!=status)
{
vis[newidx]=status;
q.push(newidx);
dist[newidx]=dist[curr]+cost;
if(max_dist<dist[newidx])
{
max_dist=dist[newidx];
index=newidx;
}
}
}
}
return index;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
int ans=0,tmp,end;
memset(vis,0,sizeof(vis));
memset(dist,0,sizeof(dist));
for(int i=0; i<M; i++)
{
int a=A[i];
int b=B[i];
int cena=T[i];
graph[a].push_back({b,cena});
graph[b].push_back({a,cena});
}
for(int i=0; i<N; i++)
{
if(vis[i]==0)
{
int y=FindEnd(i,1);
int x=FindEnd(y,2);
tmp=end=dist[x];
if(ans<tmp)
{
ans=tmp;
}
while(dist[x]>0)
{
for(int j=0; j<(int)graph[x].size(); j++)
{
y=graph[x][j].first;
if(dist[x]==dist[y]+graph[x][j].second)
{
x=y;
break;
}
}
tmp=min(tmp,max(dist[x],end-dist[x]));
}
radius.push_back(tmp);
}
}
sort(radius.begin(),radius.end());
if (radius.size() == 2) ans = max(ans,radius[0]+radius[1]+L);
else if (radius.size() > 2)
{
int last = max(radius[0]+radius[1],radius[1]+radius[2]+L);
last = min(max(radius[1]+radius[0],radius[0]+radius[2]+L),last);
last = min(max(radius[2]+radius[0],radius[0]+radius[1]+L),last);
ans = max(ans,last+L);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
7328 KB |
Output is correct |
2 |
Correct |
38 ms |
7252 KB |
Output is correct |
3 |
Correct |
29 ms |
5972 KB |
Output is correct |
4 |
Correct |
8 ms |
3924 KB |
Output is correct |
5 |
Correct |
6 ms |
3796 KB |
Output is correct |
6 |
Correct |
12 ms |
4228 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
24 ms |
5188 KB |
Output is correct |
9 |
Correct |
33 ms |
5576 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
42 ms |
6352 KB |
Output is correct |
12 |
Correct |
51 ms |
6868 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3412 KB |
Output is correct |
2 |
Correct |
3 ms |
3412 KB |
Output is correct |
3 |
Correct |
3 ms |
3412 KB |
Output is correct |
4 |
Correct |
3 ms |
3412 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
2 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3412 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Correct |
2 ms |
3412 KB |
Output is correct |
18 |
Correct |
2 ms |
3412 KB |
Output is correct |
19 |
Correct |
2 ms |
3412 KB |
Output is correct |
20 |
Correct |
2 ms |
3412 KB |
Output is correct |
21 |
Correct |
2 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3412 KB |
Output is correct |
23 |
Correct |
2 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3412 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
7328 KB |
Output is correct |
2 |
Correct |
38 ms |
7252 KB |
Output is correct |
3 |
Correct |
29 ms |
5972 KB |
Output is correct |
4 |
Correct |
8 ms |
3924 KB |
Output is correct |
5 |
Correct |
6 ms |
3796 KB |
Output is correct |
6 |
Correct |
12 ms |
4228 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
24 ms |
5188 KB |
Output is correct |
9 |
Correct |
33 ms |
5576 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
42 ms |
6352 KB |
Output is correct |
12 |
Correct |
51 ms |
6868 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
3 ms |
3412 KB |
Output is correct |
15 |
Correct |
3 ms |
3412 KB |
Output is correct |
16 |
Correct |
3 ms |
3412 KB |
Output is correct |
17 |
Correct |
3 ms |
3412 KB |
Output is correct |
18 |
Correct |
3 ms |
3412 KB |
Output is correct |
19 |
Correct |
2 ms |
3412 KB |
Output is correct |
20 |
Correct |
2 ms |
3412 KB |
Output is correct |
21 |
Correct |
2 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3412 KB |
Output is correct |
23 |
Correct |
2 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3412 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
2 ms |
3412 KB |
Output is correct |
27 |
Correct |
2 ms |
3412 KB |
Output is correct |
28 |
Correct |
2 ms |
3412 KB |
Output is correct |
29 |
Correct |
2 ms |
3412 KB |
Output is correct |
30 |
Correct |
2 ms |
3412 KB |
Output is correct |
31 |
Correct |
2 ms |
3412 KB |
Output is correct |
32 |
Correct |
2 ms |
3412 KB |
Output is correct |
33 |
Correct |
2 ms |
3412 KB |
Output is correct |
34 |
Correct |
2 ms |
3412 KB |
Output is correct |
35 |
Correct |
2 ms |
3412 KB |
Output is correct |
36 |
Correct |
2 ms |
3412 KB |
Output is correct |
37 |
Correct |
2 ms |
3412 KB |
Output is correct |
38 |
Correct |
2 ms |
3412 KB |
Output is correct |
39 |
Correct |
43 ms |
7356 KB |
Output is correct |
40 |
Correct |
55 ms |
7244 KB |
Output is correct |
41 |
Correct |
28 ms |
6004 KB |
Output is correct |
42 |
Correct |
7 ms |
4024 KB |
Output is correct |
43 |
Correct |
3 ms |
3412 KB |
Output is correct |
44 |
Correct |
2 ms |
3412 KB |
Output is correct |
45 |
Correct |
2 ms |
3412 KB |
Output is correct |
46 |
Correct |
2 ms |
3412 KB |
Output is correct |
47 |
Correct |
2 ms |
3412 KB |
Output is correct |
48 |
Correct |
2 ms |
3412 KB |
Output is correct |
49 |
Correct |
2 ms |
3412 KB |
Output is correct |
50 |
Correct |
2 ms |
3412 KB |
Output is correct |
51 |
Correct |
2 ms |
3412 KB |
Output is correct |
52 |
Correct |
2 ms |
3412 KB |
Output is correct |
53 |
Correct |
2 ms |
3412 KB |
Output is correct |
54 |
Correct |
2 ms |
3412 KB |
Output is correct |
55 |
Correct |
2 ms |
3412 KB |
Output is correct |
56 |
Correct |
2 ms |
3412 KB |
Output is correct |
57 |
Correct |
54 ms |
8524 KB |
Output is correct |
58 |
Correct |
70 ms |
8520 KB |
Output is correct |
59 |
Correct |
68 ms |
8420 KB |
Output is correct |
60 |
Correct |
58 ms |
8424 KB |
Output is correct |
61 |
Correct |
60 ms |
8360 KB |
Output is correct |
62 |
Correct |
61 ms |
8384 KB |
Output is correct |
63 |
Correct |
57 ms |
8268 KB |
Output is correct |
64 |
Correct |
48 ms |
8268 KB |
Output is correct |
65 |
Correct |
56 ms |
8252 KB |
Output is correct |
66 |
Correct |
58 ms |
8316 KB |
Output is correct |
67 |
Correct |
50 ms |
8396 KB |
Output is correct |
68 |
Correct |
54 ms |
8420 KB |
Output is correct |
69 |
Correct |
70 ms |
8492 KB |
Output is correct |
70 |
Correct |
66 ms |
8428 KB |
Output is correct |
71 |
Correct |
2 ms |
3412 KB |
Output is correct |
72 |
Correct |
3 ms |
3540 KB |
Output is correct |
73 |
Correct |
3 ms |
3540 KB |
Output is correct |
74 |
Correct |
3 ms |
3540 KB |
Output is correct |
75 |
Correct |
3 ms |
3540 KB |
Output is correct |
76 |
Correct |
3 ms |
3540 KB |
Output is correct |
77 |
Correct |
3 ms |
3540 KB |
Output is correct |
78 |
Correct |
3 ms |
3540 KB |
Output is correct |
79 |
Correct |
3 ms |
3540 KB |
Output is correct |
80 |
Correct |
53 ms |
8324 KB |
Output is correct |
81 |
Correct |
61 ms |
8404 KB |
Output is correct |
82 |
Correct |
51 ms |
8408 KB |
Output is correct |
83 |
Correct |
58 ms |
8384 KB |
Output is correct |
84 |
Correct |
3 ms |
3540 KB |
Output is correct |
85 |
Correct |
3 ms |
3540 KB |
Output is correct |
86 |
Correct |
4 ms |
3512 KB |
Output is correct |
87 |
Correct |
3 ms |
3540 KB |
Output is correct |
88 |
Correct |
3 ms |
3540 KB |
Output is correct |
89 |
Correct |
3 ms |
3540 KB |
Output is correct |
90 |
Correct |
3 ms |
3540 KB |
Output is correct |
91 |
Correct |
3 ms |
3540 KB |
Output is correct |
92 |
Correct |
3 ms |
3540 KB |
Output is correct |
93 |
Correct |
3 ms |
3540 KB |
Output is correct |
94 |
Correct |
2 ms |
3412 KB |
Output is correct |
95 |
Correct |
2 ms |
3412 KB |
Output is correct |
96 |
Correct |
3 ms |
3412 KB |
Output is correct |
97 |
Correct |
2 ms |
3412 KB |
Output is correct |
98 |
Correct |
2 ms |
3412 KB |
Output is correct |
99 |
Correct |
2 ms |
3412 KB |
Output is correct |
100 |
Correct |
2 ms |
3452 KB |
Output is correct |
101 |
Correct |
2 ms |
3412 KB |
Output is correct |
102 |
Correct |
2 ms |
3412 KB |
Output is correct |
103 |
Correct |
2 ms |
3412 KB |
Output is correct |
104 |
Correct |
6 ms |
3796 KB |
Output is correct |
105 |
Correct |
11 ms |
4204 KB |
Output is correct |
106 |
Correct |
2 ms |
3412 KB |
Output is correct |
107 |
Correct |
20 ms |
5076 KB |
Output is correct |
108 |
Correct |
26 ms |
5564 KB |
Output is correct |
109 |
Correct |
2 ms |
3412 KB |
Output is correct |
110 |
Correct |
47 ms |
6420 KB |
Output is correct |
111 |
Correct |
63 ms |
6876 KB |
Output is correct |
112 |
Correct |
2 ms |
3464 KB |
Output is correct |
113 |
Correct |
76 ms |
7700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
6140 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3412 KB |
Output is correct |
2 |
Correct |
3 ms |
3412 KB |
Output is correct |
3 |
Correct |
3 ms |
3412 KB |
Output is correct |
4 |
Correct |
3 ms |
3412 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
2 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3412 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Correct |
2 ms |
3412 KB |
Output is correct |
18 |
Correct |
2 ms |
3412 KB |
Output is correct |
19 |
Correct |
2 ms |
3412 KB |
Output is correct |
20 |
Correct |
2 ms |
3412 KB |
Output is correct |
21 |
Correct |
2 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3412 KB |
Output is correct |
23 |
Correct |
2 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3412 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
2 ms |
3412 KB |
Output is correct |
27 |
Correct |
3 ms |
3540 KB |
Output is correct |
28 |
Correct |
3 ms |
3540 KB |
Output is correct |
29 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
7328 KB |
Output is correct |
2 |
Correct |
38 ms |
7252 KB |
Output is correct |
3 |
Correct |
29 ms |
5972 KB |
Output is correct |
4 |
Correct |
8 ms |
3924 KB |
Output is correct |
5 |
Correct |
6 ms |
3796 KB |
Output is correct |
6 |
Correct |
12 ms |
4228 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
24 ms |
5188 KB |
Output is correct |
9 |
Correct |
33 ms |
5576 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
42 ms |
6352 KB |
Output is correct |
12 |
Correct |
51 ms |
6868 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
3 ms |
3412 KB |
Output is correct |
15 |
Correct |
3 ms |
3412 KB |
Output is correct |
16 |
Correct |
3 ms |
3412 KB |
Output is correct |
17 |
Correct |
3 ms |
3412 KB |
Output is correct |
18 |
Correct |
3 ms |
3412 KB |
Output is correct |
19 |
Correct |
2 ms |
3412 KB |
Output is correct |
20 |
Correct |
2 ms |
3412 KB |
Output is correct |
21 |
Correct |
2 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3412 KB |
Output is correct |
23 |
Correct |
2 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3412 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
2 ms |
3412 KB |
Output is correct |
27 |
Correct |
2 ms |
3412 KB |
Output is correct |
28 |
Correct |
2 ms |
3412 KB |
Output is correct |
29 |
Correct |
2 ms |
3412 KB |
Output is correct |
30 |
Correct |
2 ms |
3412 KB |
Output is correct |
31 |
Correct |
2 ms |
3412 KB |
Output is correct |
32 |
Correct |
2 ms |
3412 KB |
Output is correct |
33 |
Correct |
2 ms |
3412 KB |
Output is correct |
34 |
Correct |
2 ms |
3412 KB |
Output is correct |
35 |
Correct |
2 ms |
3412 KB |
Output is correct |
36 |
Correct |
2 ms |
3412 KB |
Output is correct |
37 |
Correct |
2 ms |
3412 KB |
Output is correct |
38 |
Correct |
2 ms |
3412 KB |
Output is correct |
39 |
Correct |
43 ms |
7356 KB |
Output is correct |
40 |
Correct |
55 ms |
7244 KB |
Output is correct |
41 |
Correct |
28 ms |
6004 KB |
Output is correct |
42 |
Correct |
7 ms |
4024 KB |
Output is correct |
43 |
Correct |
3 ms |
3412 KB |
Output is correct |
44 |
Correct |
2 ms |
3412 KB |
Output is correct |
45 |
Correct |
2 ms |
3412 KB |
Output is correct |
46 |
Correct |
2 ms |
3412 KB |
Output is correct |
47 |
Correct |
2 ms |
3412 KB |
Output is correct |
48 |
Correct |
2 ms |
3412 KB |
Output is correct |
49 |
Correct |
2 ms |
3412 KB |
Output is correct |
50 |
Correct |
2 ms |
3412 KB |
Output is correct |
51 |
Correct |
2 ms |
3412 KB |
Output is correct |
52 |
Correct |
2 ms |
3412 KB |
Output is correct |
53 |
Correct |
2 ms |
3412 KB |
Output is correct |
54 |
Correct |
2 ms |
3412 KB |
Output is correct |
55 |
Correct |
2 ms |
3412 KB |
Output is correct |
56 |
Correct |
2 ms |
3412 KB |
Output is correct |
57 |
Correct |
54 ms |
8524 KB |
Output is correct |
58 |
Correct |
70 ms |
8520 KB |
Output is correct |
59 |
Correct |
68 ms |
8420 KB |
Output is correct |
60 |
Correct |
58 ms |
8424 KB |
Output is correct |
61 |
Correct |
60 ms |
8360 KB |
Output is correct |
62 |
Correct |
61 ms |
8384 KB |
Output is correct |
63 |
Correct |
57 ms |
8268 KB |
Output is correct |
64 |
Correct |
48 ms |
8268 KB |
Output is correct |
65 |
Correct |
56 ms |
8252 KB |
Output is correct |
66 |
Correct |
58 ms |
8316 KB |
Output is correct |
67 |
Correct |
50 ms |
8396 KB |
Output is correct |
68 |
Correct |
54 ms |
8420 KB |
Output is correct |
69 |
Correct |
70 ms |
8492 KB |
Output is correct |
70 |
Correct |
66 ms |
8428 KB |
Output is correct |
71 |
Correct |
2 ms |
3412 KB |
Output is correct |
72 |
Correct |
3 ms |
3540 KB |
Output is correct |
73 |
Correct |
3 ms |
3540 KB |
Output is correct |
74 |
Correct |
3 ms |
3540 KB |
Output is correct |
75 |
Correct |
3 ms |
3540 KB |
Output is correct |
76 |
Correct |
3 ms |
3540 KB |
Output is correct |
77 |
Correct |
3 ms |
3540 KB |
Output is correct |
78 |
Correct |
3 ms |
3540 KB |
Output is correct |
79 |
Correct |
3 ms |
3540 KB |
Output is correct |
80 |
Correct |
53 ms |
8324 KB |
Output is correct |
81 |
Correct |
61 ms |
8404 KB |
Output is correct |
82 |
Correct |
51 ms |
8408 KB |
Output is correct |
83 |
Correct |
58 ms |
8384 KB |
Output is correct |
84 |
Correct |
3 ms |
3540 KB |
Output is correct |
85 |
Correct |
3 ms |
3540 KB |
Output is correct |
86 |
Correct |
4 ms |
3512 KB |
Output is correct |
87 |
Correct |
3 ms |
3540 KB |
Output is correct |
88 |
Correct |
3 ms |
3540 KB |
Output is correct |
89 |
Correct |
3 ms |
3540 KB |
Output is correct |
90 |
Correct |
3 ms |
3540 KB |
Output is correct |
91 |
Correct |
3 ms |
3540 KB |
Output is correct |
92 |
Correct |
3 ms |
3540 KB |
Output is correct |
93 |
Correct |
3 ms |
3540 KB |
Output is correct |
94 |
Correct |
2 ms |
3412 KB |
Output is correct |
95 |
Correct |
2 ms |
3412 KB |
Output is correct |
96 |
Correct |
3 ms |
3412 KB |
Output is correct |
97 |
Correct |
2 ms |
3412 KB |
Output is correct |
98 |
Correct |
2 ms |
3412 KB |
Output is correct |
99 |
Correct |
2 ms |
3412 KB |
Output is correct |
100 |
Correct |
2 ms |
3452 KB |
Output is correct |
101 |
Correct |
2 ms |
3412 KB |
Output is correct |
102 |
Correct |
2 ms |
3412 KB |
Output is correct |
103 |
Correct |
2 ms |
3412 KB |
Output is correct |
104 |
Correct |
6 ms |
3796 KB |
Output is correct |
105 |
Correct |
11 ms |
4204 KB |
Output is correct |
106 |
Correct |
2 ms |
3412 KB |
Output is correct |
107 |
Correct |
20 ms |
5076 KB |
Output is correct |
108 |
Correct |
26 ms |
5564 KB |
Output is correct |
109 |
Correct |
2 ms |
3412 KB |
Output is correct |
110 |
Correct |
47 ms |
6420 KB |
Output is correct |
111 |
Correct |
63 ms |
6876 KB |
Output is correct |
112 |
Correct |
2 ms |
3464 KB |
Output is correct |
113 |
Correct |
76 ms |
7700 KB |
Output is correct |
114 |
Incorrect |
28 ms |
6140 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |