#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 7;
int val,ve;
bool used[maxN];
vector<pair<int, int>> v[maxN];
void dfs(int x, int p, int sum)
{
used[x] = true;
if(sum >= val){
val = sum;
ve = x;
}
for(auto y : v[x]){
if(y.first != p){
dfs(y.first, x, sum + y.second);
}
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
for(int i = 0; i < M; i++){
v[A[i]].push_back({B[i], T[i]});
v[B[i]].push_back({A[i], T[i]});
}
vector<int> p(N, -1);
vector<int> d(N, 1e9);
vector<pair<int, int>> X;
for(int i = 0; i < N; i++){
if(!used[i]){
val = ve = 0;
dfs(i, i, 0);
int r1 = ve;
val = ve = 0;
dfs(r1, r1, 0);
int r2 = ve;
queue<int> q;
q.push(r1);
d[r1] = 0;
while(!q.empty()){
int x = q.front();
q.pop();
for(auto y : v[x]){
if(d[y.first] == 1e9){
d[y.first] = d[x] + 1;
p[y.first] = x;
q.push(y.first);
}
}
}
vector<int> pa;
while(r2 != r1){
pa.push_back(r2);
r2 = p[r2];
}
pa.push_back(r1);
int v1 = 0;
int res = 1e9;
for(int j = max(0, (int)pa.size() / 2 - 10); j < min((int)pa.size(), (int)pa.size() / 2 + 10); j++){
int st = pa[j];
queue<int> q;
q.push(st);
unordered_map<int, int> d;
int mx = 0;
d[st] = 0;
while(!q.empty()){
int x = q.front();
q.pop();
for(auto y : v[x]){
if(d.find(y.first) == d.end()){
d[y.first] = d[x] + y.second;
q.push(y.first);
mx = max(mx, d[x] + y.second);
}
}
}
if(mx < res){
res = mx;
v1 = st;
}
}
X.push_back({res, v1});
}
}
sort(X.rbegin(), X.rend());
for(int i = 1; i < (int)X.size(); i++){
v[X[0].second].push_back({X[i].second, L});
v[X[i].second].push_back({X[0].second, L});
}
val = ve = 0;
dfs(0, 0, 0);
val = 0;
dfs(ve, ve, 0);
return val;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
517 ms |
16948 KB |
Output is correct |
2 |
Correct |
511 ms |
16724 KB |
Output is correct |
3 |
Correct |
257 ms |
11444 KB |
Output is correct |
4 |
Correct |
52 ms |
4600 KB |
Output is correct |
5 |
Correct |
41 ms |
3676 KB |
Output is correct |
6 |
Correct |
102 ms |
5472 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
182 ms |
7136 KB |
Output is correct |
9 |
Correct |
224 ms |
8860 KB |
Output is correct |
10 |
Correct |
4 ms |
2636 KB |
Output is correct |
11 |
Correct |
402 ms |
11024 KB |
Output is correct |
12 |
Correct |
528 ms |
13112 KB |
Output is correct |
13 |
Correct |
5 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2544 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
17 |
Correct |
2 ms |
2636 KB |
Output is correct |
18 |
Correct |
2 ms |
2636 KB |
Output is correct |
19 |
Correct |
2 ms |
2636 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2636 KB |
Output is correct |
22 |
Correct |
2 ms |
2636 KB |
Output is correct |
23 |
Correct |
2 ms |
2636 KB |
Output is correct |
24 |
Correct |
2 ms |
2636 KB |
Output is correct |
25 |
Correct |
3 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
517 ms |
16948 KB |
Output is correct |
2 |
Correct |
511 ms |
16724 KB |
Output is correct |
3 |
Correct |
257 ms |
11444 KB |
Output is correct |
4 |
Correct |
52 ms |
4600 KB |
Output is correct |
5 |
Correct |
41 ms |
3676 KB |
Output is correct |
6 |
Correct |
102 ms |
5472 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
182 ms |
7136 KB |
Output is correct |
9 |
Correct |
224 ms |
8860 KB |
Output is correct |
10 |
Correct |
4 ms |
2636 KB |
Output is correct |
11 |
Correct |
402 ms |
11024 KB |
Output is correct |
12 |
Correct |
528 ms |
13112 KB |
Output is correct |
13 |
Correct |
5 ms |
2764 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
17 |
Correct |
2 ms |
2636 KB |
Output is correct |
18 |
Correct |
2 ms |
2636 KB |
Output is correct |
19 |
Correct |
2 ms |
2636 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2636 KB |
Output is correct |
22 |
Correct |
2 ms |
2636 KB |
Output is correct |
23 |
Correct |
2 ms |
2636 KB |
Output is correct |
24 |
Correct |
2 ms |
2636 KB |
Output is correct |
25 |
Correct |
2 ms |
2636 KB |
Output is correct |
26 |
Correct |
2 ms |
2636 KB |
Output is correct |
27 |
Correct |
2 ms |
2636 KB |
Output is correct |
28 |
Correct |
2 ms |
2544 KB |
Output is correct |
29 |
Correct |
2 ms |
2636 KB |
Output is correct |
30 |
Correct |
2 ms |
2636 KB |
Output is correct |
31 |
Correct |
2 ms |
2636 KB |
Output is correct |
32 |
Correct |
2 ms |
2636 KB |
Output is correct |
33 |
Correct |
2 ms |
2636 KB |
Output is correct |
34 |
Correct |
2 ms |
2636 KB |
Output is correct |
35 |
Correct |
2 ms |
2636 KB |
Output is correct |
36 |
Correct |
2 ms |
2636 KB |
Output is correct |
37 |
Correct |
2 ms |
2636 KB |
Output is correct |
38 |
Correct |
3 ms |
2636 KB |
Output is correct |
39 |
Correct |
474 ms |
17960 KB |
Output is correct |
40 |
Correct |
536 ms |
17924 KB |
Output is correct |
41 |
Correct |
259 ms |
12372 KB |
Output is correct |
42 |
Correct |
50 ms |
4820 KB |
Output is correct |
43 |
Correct |
3 ms |
2636 KB |
Output is correct |
44 |
Correct |
2 ms |
2636 KB |
Output is correct |
45 |
Correct |
3 ms |
2636 KB |
Output is correct |
46 |
Correct |
2 ms |
2636 KB |
Output is correct |
47 |
Correct |
2 ms |
2636 KB |
Output is correct |
48 |
Correct |
2 ms |
2636 KB |
Output is correct |
49 |
Correct |
2 ms |
2636 KB |
Output is correct |
50 |
Correct |
2 ms |
2636 KB |
Output is correct |
51 |
Correct |
2 ms |
2636 KB |
Output is correct |
52 |
Correct |
2 ms |
2636 KB |
Output is correct |
53 |
Correct |
2 ms |
2664 KB |
Output is correct |
54 |
Correct |
3 ms |
2636 KB |
Output is correct |
55 |
Correct |
3 ms |
2636 KB |
Output is correct |
56 |
Correct |
2 ms |
2636 KB |
Output is correct |
57 |
Correct |
840 ms |
14424 KB |
Output is correct |
58 |
Incorrect |
747 ms |
12116 KB |
Output isn't correct |
59 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
7668 KB |
Output is correct |
2 |
Correct |
81 ms |
7664 KB |
Output is correct |
3 |
Correct |
76 ms |
7696 KB |
Output is correct |
4 |
Correct |
82 ms |
7784 KB |
Output is correct |
5 |
Correct |
84 ms |
7716 KB |
Output is correct |
6 |
Correct |
92 ms |
8548 KB |
Output is correct |
7 |
Correct |
83 ms |
7876 KB |
Output is correct |
8 |
Correct |
74 ms |
7556 KB |
Output is correct |
9 |
Correct |
73 ms |
7584 KB |
Output is correct |
10 |
Correct |
83 ms |
7884 KB |
Output is correct |
11 |
Correct |
3 ms |
2636 KB |
Output is correct |
12 |
Correct |
56 ms |
8176 KB |
Output is correct |
13 |
Correct |
65 ms |
8120 KB |
Output is correct |
14 |
Correct |
55 ms |
8120 KB |
Output is correct |
15 |
Correct |
55 ms |
8152 KB |
Output is correct |
16 |
Correct |
55 ms |
8152 KB |
Output is correct |
17 |
Correct |
56 ms |
8180 KB |
Output is correct |
18 |
Correct |
61 ms |
8120 KB |
Output is correct |
19 |
Correct |
55 ms |
8204 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2636 KB |
Output is correct |
22 |
Correct |
3 ms |
2764 KB |
Output is correct |
23 |
Correct |
55 ms |
8140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2544 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
17 |
Correct |
2 ms |
2636 KB |
Output is correct |
18 |
Correct |
2 ms |
2636 KB |
Output is correct |
19 |
Correct |
2 ms |
2636 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2636 KB |
Output is correct |
22 |
Correct |
2 ms |
2636 KB |
Output is correct |
23 |
Correct |
2 ms |
2636 KB |
Output is correct |
24 |
Correct |
2 ms |
2636 KB |
Output is correct |
25 |
Correct |
3 ms |
2636 KB |
Output is correct |
26 |
Correct |
3 ms |
2636 KB |
Output is correct |
27 |
Correct |
4 ms |
2764 KB |
Output is correct |
28 |
Correct |
5 ms |
2764 KB |
Output is correct |
29 |
Correct |
3 ms |
2636 KB |
Output is correct |
30 |
Correct |
5 ms |
2764 KB |
Output is correct |
31 |
Correct |
5 ms |
2764 KB |
Output is correct |
32 |
Correct |
3 ms |
2716 KB |
Output is correct |
33 |
Correct |
4 ms |
2764 KB |
Output is correct |
34 |
Correct |
5 ms |
2764 KB |
Output is correct |
35 |
Correct |
2 ms |
2636 KB |
Output is correct |
36 |
Correct |
2 ms |
2636 KB |
Output is correct |
37 |
Correct |
2 ms |
2636 KB |
Output is correct |
38 |
Correct |
2 ms |
2636 KB |
Output is correct |
39 |
Correct |
2 ms |
2628 KB |
Output is correct |
40 |
Correct |
2 ms |
2636 KB |
Output is correct |
41 |
Correct |
3 ms |
2636 KB |
Output is correct |
42 |
Correct |
2 ms |
2636 KB |
Output is correct |
43 |
Correct |
3 ms |
2636 KB |
Output is correct |
44 |
Correct |
2 ms |
2636 KB |
Output is correct |
45 |
Correct |
2 ms |
2636 KB |
Output is correct |
46 |
Correct |
2 ms |
2636 KB |
Output is correct |
47 |
Correct |
3 ms |
2636 KB |
Output is correct |
48 |
Correct |
2 ms |
2636 KB |
Output is correct |
49 |
Correct |
2 ms |
2636 KB |
Output is correct |
50 |
Correct |
2 ms |
2636 KB |
Output is correct |
51 |
Correct |
3 ms |
2636 KB |
Output is correct |
52 |
Correct |
2 ms |
2636 KB |
Output is correct |
53 |
Correct |
2 ms |
2636 KB |
Output is correct |
54 |
Correct |
12 ms |
3020 KB |
Output is correct |
55 |
Correct |
12 ms |
3020 KB |
Output is correct |
56 |
Correct |
5 ms |
2764 KB |
Output is correct |
57 |
Correct |
4 ms |
2764 KB |
Output is correct |
58 |
Correct |
13 ms |
2892 KB |
Output is correct |
59 |
Correct |
15 ms |
2892 KB |
Output is correct |
60 |
Correct |
4 ms |
2764 KB |
Output is correct |
61 |
Correct |
4 ms |
2764 KB |
Output is correct |
62 |
Correct |
13 ms |
2892 KB |
Output is correct |
63 |
Correct |
13 ms |
2896 KB |
Output is correct |
64 |
Correct |
4 ms |
2764 KB |
Output is correct |
65 |
Correct |
5 ms |
2764 KB |
Output is correct |
66 |
Correct |
12 ms |
2968 KB |
Output is correct |
67 |
Correct |
16 ms |
2920 KB |
Output is correct |
68 |
Correct |
5 ms |
2796 KB |
Output is correct |
69 |
Correct |
7 ms |
2764 KB |
Output is correct |
70 |
Correct |
5 ms |
2764 KB |
Output is correct |
71 |
Correct |
4 ms |
2764 KB |
Output is correct |
72 |
Correct |
13 ms |
2964 KB |
Output is correct |
73 |
Correct |
13 ms |
2960 KB |
Output is correct |
74 |
Correct |
9 ms |
2764 KB |
Output is correct |
75 |
Correct |
10 ms |
2836 KB |
Output is correct |
76 |
Correct |
13 ms |
2928 KB |
Output is correct |
77 |
Correct |
13 ms |
2892 KB |
Output is correct |
78 |
Correct |
4 ms |
2764 KB |
Output is correct |
79 |
Correct |
4 ms |
2764 KB |
Output is correct |
80 |
Correct |
3 ms |
2764 KB |
Output is correct |
81 |
Correct |
3 ms |
2764 KB |
Output is correct |
82 |
Correct |
7 ms |
2764 KB |
Output is correct |
83 |
Correct |
7 ms |
2824 KB |
Output is correct |
84 |
Correct |
6 ms |
2788 KB |
Output is correct |
85 |
Correct |
5 ms |
2764 KB |
Output is correct |
86 |
Correct |
11 ms |
2764 KB |
Output is correct |
87 |
Correct |
12 ms |
2964 KB |
Output is correct |
88 |
Correct |
5 ms |
2764 KB |
Output is correct |
89 |
Correct |
5 ms |
2764 KB |
Output is correct |
90 |
Correct |
4 ms |
2764 KB |
Output is correct |
91 |
Correct |
4 ms |
2764 KB |
Output is correct |
92 |
Correct |
6 ms |
2872 KB |
Output is correct |
93 |
Correct |
7 ms |
2764 KB |
Output is correct |
94 |
Correct |
9 ms |
2880 KB |
Output is correct |
95 |
Correct |
14 ms |
2764 KB |
Output is correct |
96 |
Correct |
9 ms |
2764 KB |
Output is correct |
97 |
Correct |
9 ms |
2892 KB |
Output is correct |
98 |
Correct |
12 ms |
2888 KB |
Output is correct |
99 |
Correct |
13 ms |
2892 KB |
Output is correct |
100 |
Correct |
12 ms |
2912 KB |
Output is correct |
101 |
Correct |
10 ms |
2892 KB |
Output is correct |
102 |
Correct |
2 ms |
2636 KB |
Output is correct |
103 |
Correct |
2 ms |
2636 KB |
Output is correct |
104 |
Correct |
3 ms |
2636 KB |
Output is correct |
105 |
Correct |
2 ms |
2636 KB |
Output is correct |
106 |
Correct |
2 ms |
2636 KB |
Output is correct |
107 |
Correct |
2 ms |
2636 KB |
Output is correct |
108 |
Correct |
2 ms |
2636 KB |
Output is correct |
109 |
Correct |
2 ms |
2636 KB |
Output is correct |
110 |
Correct |
2 ms |
2636 KB |
Output is correct |
111 |
Correct |
2 ms |
2636 KB |
Output is correct |
112 |
Correct |
3 ms |
2708 KB |
Output is correct |
113 |
Correct |
4 ms |
2636 KB |
Output is correct |
114 |
Correct |
5 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
517 ms |
16948 KB |
Output is correct |
2 |
Correct |
511 ms |
16724 KB |
Output is correct |
3 |
Correct |
257 ms |
11444 KB |
Output is correct |
4 |
Correct |
52 ms |
4600 KB |
Output is correct |
5 |
Correct |
41 ms |
3676 KB |
Output is correct |
6 |
Correct |
102 ms |
5472 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
182 ms |
7136 KB |
Output is correct |
9 |
Correct |
224 ms |
8860 KB |
Output is correct |
10 |
Correct |
4 ms |
2636 KB |
Output is correct |
11 |
Correct |
402 ms |
11024 KB |
Output is correct |
12 |
Correct |
528 ms |
13112 KB |
Output is correct |
13 |
Correct |
5 ms |
2764 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
17 |
Correct |
2 ms |
2636 KB |
Output is correct |
18 |
Correct |
2 ms |
2636 KB |
Output is correct |
19 |
Correct |
2 ms |
2636 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2636 KB |
Output is correct |
22 |
Correct |
2 ms |
2636 KB |
Output is correct |
23 |
Correct |
2 ms |
2636 KB |
Output is correct |
24 |
Correct |
2 ms |
2636 KB |
Output is correct |
25 |
Correct |
2 ms |
2636 KB |
Output is correct |
26 |
Correct |
2 ms |
2636 KB |
Output is correct |
27 |
Correct |
2 ms |
2636 KB |
Output is correct |
28 |
Correct |
2 ms |
2544 KB |
Output is correct |
29 |
Correct |
2 ms |
2636 KB |
Output is correct |
30 |
Correct |
2 ms |
2636 KB |
Output is correct |
31 |
Correct |
2 ms |
2636 KB |
Output is correct |
32 |
Correct |
2 ms |
2636 KB |
Output is correct |
33 |
Correct |
2 ms |
2636 KB |
Output is correct |
34 |
Correct |
2 ms |
2636 KB |
Output is correct |
35 |
Correct |
2 ms |
2636 KB |
Output is correct |
36 |
Correct |
2 ms |
2636 KB |
Output is correct |
37 |
Correct |
2 ms |
2636 KB |
Output is correct |
38 |
Correct |
3 ms |
2636 KB |
Output is correct |
39 |
Correct |
474 ms |
17960 KB |
Output is correct |
40 |
Correct |
536 ms |
17924 KB |
Output is correct |
41 |
Correct |
259 ms |
12372 KB |
Output is correct |
42 |
Correct |
50 ms |
4820 KB |
Output is correct |
43 |
Correct |
3 ms |
2636 KB |
Output is correct |
44 |
Correct |
2 ms |
2636 KB |
Output is correct |
45 |
Correct |
3 ms |
2636 KB |
Output is correct |
46 |
Correct |
2 ms |
2636 KB |
Output is correct |
47 |
Correct |
2 ms |
2636 KB |
Output is correct |
48 |
Correct |
2 ms |
2636 KB |
Output is correct |
49 |
Correct |
2 ms |
2636 KB |
Output is correct |
50 |
Correct |
2 ms |
2636 KB |
Output is correct |
51 |
Correct |
2 ms |
2636 KB |
Output is correct |
52 |
Correct |
2 ms |
2636 KB |
Output is correct |
53 |
Correct |
2 ms |
2664 KB |
Output is correct |
54 |
Correct |
3 ms |
2636 KB |
Output is correct |
55 |
Correct |
3 ms |
2636 KB |
Output is correct |
56 |
Correct |
2 ms |
2636 KB |
Output is correct |
57 |
Correct |
840 ms |
14424 KB |
Output is correct |
58 |
Incorrect |
747 ms |
12116 KB |
Output isn't correct |
59 |
Halted |
0 ms |
0 KB |
- |