#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include "dreaming.h"
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
pii calcDist(int i, vvpii & G, vector<bool> & visited, vi & dist1, vi & dist2) {
queue<int> Q;
Q.push(i);
int u, v, t, N = (int) G.size(), maxNode = i;
vector<int> vertices = {};
dist1[i] = 0;
while(!Q.empty()) {
u = Q.front();
Q.pop();
visited[u] = true;
vertices.push_back(u);
if (dist1[u] > dist1[maxNode])
maxNode = u;
for (auto connection: G[u]) {
v = connection.first;
t = connection.second;
if (dist1[v] > dist1[u]+t) {
dist1[v] = dist1[u]+t;
Q.push(v);
}
}
}
dist2[maxNode] = 0;
Q.push(maxNode);
while(!Q.empty()) {
u = Q.front();
Q.pop();
if (dist2[u] > dist2[maxNode])
maxNode = u;
for (auto connection: G[u]) {
v = connection.first;
t = connection.second;
if (dist2[v] > dist2[u]+t) {
dist2[v] = dist2[u]+t;
Q.push(v);
}
}
}
int diam = dist2[maxNode];
dist1.assign(N, 1e9);
dist1[maxNode] = 0;
Q.push(maxNode);
while(!Q.empty()) {
u = Q.front();
Q.pop();
for (auto connection: G[u]) {
v = connection.first;
t = connection.second;
if (dist1[v] > dist1[u]+t) {
dist1[v] = dist1[u]+t;
Q.push(v);
}
}
}
int ecc = 1e9;
for (auto vert: vertices) {
//cout << vert << " " << dist1[vert] << " " << dist2[vert] << "\n";
ecc = min(ecc, max(dist1[vert], dist2[vert]));
}
return make_pair(ecc, diam);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
vvpii G(N, vpii());
vector<bool> visited(N, false);
for (int i = 0; i < M; i++) {
G[A[i]].push_back(make_pair(B[i], T[i]));
G[B[i]].push_back(make_pair(A[i], T[i]));
}
int CC = 0;
vi diam = {}, ecc = {}, dist1(N, 1e9), dist2(N, 1e9);
pii curCC;
for (int i = 0; i < N; i++) {
if (!visited[i]) {
curCC = calcDist(i, G, visited, dist1, dist2);
ecc.push_back(curCC.first);
diam.push_back(curCC.second);
//cout << i << " " << ecc[CC] << " " << diam[CC] << "\n";
CC++;
}
}
int ans = diam[0];
for (int i = 1; i < CC; i++)
ans = max(ans, diam[i]);
sort(ecc.begin(), ecc.end(), greater<int>());
for (int i = 1; i < CC; i++)
ans = max(ans, ecc[i]+ecc[0]+L);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
7792 KB |
Output is correct |
2 |
Correct |
53 ms |
7788 KB |
Output is correct |
3 |
Correct |
36 ms |
5228 KB |
Output is correct |
4 |
Correct |
7 ms |
1388 KB |
Output is correct |
5 |
Correct |
6 ms |
1132 KB |
Output is correct |
6 |
Correct |
13 ms |
2028 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
27 ms |
4076 KB |
Output is correct |
9 |
Correct |
36 ms |
5104 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
58 ms |
7148 KB |
Output is correct |
12 |
Correct |
69 ms |
8036 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
7792 KB |
Output is correct |
2 |
Correct |
53 ms |
7788 KB |
Output is correct |
3 |
Correct |
36 ms |
5228 KB |
Output is correct |
4 |
Correct |
7 ms |
1388 KB |
Output is correct |
5 |
Correct |
6 ms |
1132 KB |
Output is correct |
6 |
Correct |
13 ms |
2028 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
27 ms |
4076 KB |
Output is correct |
9 |
Correct |
36 ms |
5104 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
58 ms |
7148 KB |
Output is correct |
12 |
Correct |
69 ms |
8036 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
0 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
7792 KB |
Output is correct |
2 |
Correct |
53 ms |
7788 KB |
Output is correct |
3 |
Correct |
36 ms |
5228 KB |
Output is correct |
4 |
Correct |
7 ms |
1388 KB |
Output is correct |
5 |
Correct |
6 ms |
1132 KB |
Output is correct |
6 |
Correct |
13 ms |
2028 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
27 ms |
4076 KB |
Output is correct |
9 |
Correct |
36 ms |
5104 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
58 ms |
7148 KB |
Output is correct |
12 |
Correct |
69 ms |
8036 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
0 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
56 ms |
9072 KB |
Output is correct |
40 |
Correct |
55 ms |
8940 KB |
Output is correct |
41 |
Correct |
34 ms |
6124 KB |
Output is correct |
42 |
Correct |
8 ms |
1644 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
1 ms |
364 KB |
Output is correct |
45 |
Correct |
1 ms |
364 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
1 ms |
364 KB |
Output is correct |
50 |
Correct |
1 ms |
364 KB |
Output is correct |
51 |
Correct |
1 ms |
364 KB |
Output is correct |
52 |
Correct |
1 ms |
364 KB |
Output is correct |
53 |
Correct |
1 ms |
364 KB |
Output is correct |
54 |
Correct |
1 ms |
364 KB |
Output is correct |
55 |
Correct |
1 ms |
364 KB |
Output is correct |
56 |
Correct |
1 ms |
364 KB |
Output is correct |
57 |
Correct |
105 ms |
10600 KB |
Output is correct |
58 |
Correct |
102 ms |
10380 KB |
Output is correct |
59 |
Correct |
92 ms |
10472 KB |
Output is correct |
60 |
Correct |
97 ms |
10272 KB |
Output is correct |
61 |
Correct |
92 ms |
10600 KB |
Output is correct |
62 |
Correct |
93 ms |
10460 KB |
Output is correct |
63 |
Correct |
86 ms |
10384 KB |
Output is correct |
64 |
Correct |
91 ms |
10396 KB |
Output is correct |
65 |
Correct |
90 ms |
10600 KB |
Output is correct |
66 |
Correct |
89 ms |
10656 KB |
Output is correct |
67 |
Correct |
96 ms |
10472 KB |
Output is correct |
68 |
Correct |
96 ms |
10472 KB |
Output is correct |
69 |
Correct |
109 ms |
10564 KB |
Output is correct |
70 |
Correct |
100 ms |
10628 KB |
Output is correct |
71 |
Correct |
1 ms |
364 KB |
Output is correct |
72 |
Correct |
2 ms |
620 KB |
Output is correct |
73 |
Correct |
2 ms |
620 KB |
Output is correct |
74 |
Correct |
2 ms |
620 KB |
Output is correct |
75 |
Correct |
2 ms |
620 KB |
Output is correct |
76 |
Correct |
2 ms |
620 KB |
Output is correct |
77 |
Correct |
2 ms |
620 KB |
Output is correct |
78 |
Correct |
2 ms |
620 KB |
Output is correct |
79 |
Correct |
2 ms |
620 KB |
Output is correct |
80 |
Correct |
98 ms |
10480 KB |
Output is correct |
81 |
Correct |
95 ms |
10472 KB |
Output is correct |
82 |
Correct |
91 ms |
10600 KB |
Output is correct |
83 |
Correct |
95 ms |
10600 KB |
Output is correct |
84 |
Correct |
2 ms |
640 KB |
Output is correct |
85 |
Correct |
2 ms |
492 KB |
Output is correct |
86 |
Correct |
2 ms |
620 KB |
Output is correct |
87 |
Correct |
2 ms |
620 KB |
Output is correct |
88 |
Correct |
2 ms |
620 KB |
Output is correct |
89 |
Correct |
2 ms |
620 KB |
Output is correct |
90 |
Correct |
2 ms |
620 KB |
Output is correct |
91 |
Correct |
2 ms |
620 KB |
Output is correct |
92 |
Correct |
2 ms |
620 KB |
Output is correct |
93 |
Correct |
2 ms |
620 KB |
Output is correct |
94 |
Correct |
1 ms |
364 KB |
Output is correct |
95 |
Correct |
1 ms |
364 KB |
Output is correct |
96 |
Correct |
1 ms |
364 KB |
Output is correct |
97 |
Correct |
1 ms |
364 KB |
Output is correct |
98 |
Correct |
1 ms |
364 KB |
Output is correct |
99 |
Correct |
1 ms |
364 KB |
Output is correct |
100 |
Correct |
1 ms |
364 KB |
Output is correct |
101 |
Correct |
1 ms |
364 KB |
Output is correct |
102 |
Correct |
1 ms |
364 KB |
Output is correct |
103 |
Correct |
1 ms |
364 KB |
Output is correct |
104 |
Correct |
6 ms |
1260 KB |
Output is correct |
105 |
Correct |
13 ms |
2284 KB |
Output is correct |
106 |
Correct |
1 ms |
384 KB |
Output is correct |
107 |
Correct |
26 ms |
4076 KB |
Output is correct |
108 |
Correct |
38 ms |
5228 KB |
Output is correct |
109 |
Correct |
1 ms |
364 KB |
Output is correct |
110 |
Correct |
64 ms |
7152 KB |
Output is correct |
111 |
Correct |
66 ms |
8040 KB |
Output is correct |
112 |
Correct |
1 ms |
364 KB |
Output is correct |
113 |
Correct |
102 ms |
10092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1084 ms |
6228 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
7792 KB |
Output is correct |
2 |
Correct |
53 ms |
7788 KB |
Output is correct |
3 |
Correct |
36 ms |
5228 KB |
Output is correct |
4 |
Correct |
7 ms |
1388 KB |
Output is correct |
5 |
Correct |
6 ms |
1132 KB |
Output is correct |
6 |
Correct |
13 ms |
2028 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
27 ms |
4076 KB |
Output is correct |
9 |
Correct |
36 ms |
5104 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
58 ms |
7148 KB |
Output is correct |
12 |
Correct |
69 ms |
8036 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
3 ms |
620 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
3 ms |
620 KB |
Output is correct |
20 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
7792 KB |
Output is correct |
2 |
Correct |
53 ms |
7788 KB |
Output is correct |
3 |
Correct |
36 ms |
5228 KB |
Output is correct |
4 |
Correct |
7 ms |
1388 KB |
Output is correct |
5 |
Correct |
6 ms |
1132 KB |
Output is correct |
6 |
Correct |
13 ms |
2028 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
27 ms |
4076 KB |
Output is correct |
9 |
Correct |
36 ms |
5104 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
58 ms |
7148 KB |
Output is correct |
12 |
Correct |
69 ms |
8036 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
0 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
56 ms |
9072 KB |
Output is correct |
40 |
Correct |
55 ms |
8940 KB |
Output is correct |
41 |
Correct |
34 ms |
6124 KB |
Output is correct |
42 |
Correct |
8 ms |
1644 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
1 ms |
364 KB |
Output is correct |
45 |
Correct |
1 ms |
364 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
1 ms |
364 KB |
Output is correct |
50 |
Correct |
1 ms |
364 KB |
Output is correct |
51 |
Correct |
1 ms |
364 KB |
Output is correct |
52 |
Correct |
1 ms |
364 KB |
Output is correct |
53 |
Correct |
1 ms |
364 KB |
Output is correct |
54 |
Correct |
1 ms |
364 KB |
Output is correct |
55 |
Correct |
1 ms |
364 KB |
Output is correct |
56 |
Correct |
1 ms |
364 KB |
Output is correct |
57 |
Correct |
105 ms |
10600 KB |
Output is correct |
58 |
Correct |
102 ms |
10380 KB |
Output is correct |
59 |
Correct |
92 ms |
10472 KB |
Output is correct |
60 |
Correct |
97 ms |
10272 KB |
Output is correct |
61 |
Correct |
92 ms |
10600 KB |
Output is correct |
62 |
Correct |
93 ms |
10460 KB |
Output is correct |
63 |
Correct |
86 ms |
10384 KB |
Output is correct |
64 |
Correct |
91 ms |
10396 KB |
Output is correct |
65 |
Correct |
90 ms |
10600 KB |
Output is correct |
66 |
Correct |
89 ms |
10656 KB |
Output is correct |
67 |
Correct |
96 ms |
10472 KB |
Output is correct |
68 |
Correct |
96 ms |
10472 KB |
Output is correct |
69 |
Correct |
109 ms |
10564 KB |
Output is correct |
70 |
Correct |
100 ms |
10628 KB |
Output is correct |
71 |
Correct |
1 ms |
364 KB |
Output is correct |
72 |
Correct |
2 ms |
620 KB |
Output is correct |
73 |
Correct |
2 ms |
620 KB |
Output is correct |
74 |
Correct |
2 ms |
620 KB |
Output is correct |
75 |
Correct |
2 ms |
620 KB |
Output is correct |
76 |
Correct |
2 ms |
620 KB |
Output is correct |
77 |
Correct |
2 ms |
620 KB |
Output is correct |
78 |
Correct |
2 ms |
620 KB |
Output is correct |
79 |
Correct |
2 ms |
620 KB |
Output is correct |
80 |
Correct |
98 ms |
10480 KB |
Output is correct |
81 |
Correct |
95 ms |
10472 KB |
Output is correct |
82 |
Correct |
91 ms |
10600 KB |
Output is correct |
83 |
Correct |
95 ms |
10600 KB |
Output is correct |
84 |
Correct |
2 ms |
640 KB |
Output is correct |
85 |
Correct |
2 ms |
492 KB |
Output is correct |
86 |
Correct |
2 ms |
620 KB |
Output is correct |
87 |
Correct |
2 ms |
620 KB |
Output is correct |
88 |
Correct |
2 ms |
620 KB |
Output is correct |
89 |
Correct |
2 ms |
620 KB |
Output is correct |
90 |
Correct |
2 ms |
620 KB |
Output is correct |
91 |
Correct |
2 ms |
620 KB |
Output is correct |
92 |
Correct |
2 ms |
620 KB |
Output is correct |
93 |
Correct |
2 ms |
620 KB |
Output is correct |
94 |
Correct |
1 ms |
364 KB |
Output is correct |
95 |
Correct |
1 ms |
364 KB |
Output is correct |
96 |
Correct |
1 ms |
364 KB |
Output is correct |
97 |
Correct |
1 ms |
364 KB |
Output is correct |
98 |
Correct |
1 ms |
364 KB |
Output is correct |
99 |
Correct |
1 ms |
364 KB |
Output is correct |
100 |
Correct |
1 ms |
364 KB |
Output is correct |
101 |
Correct |
1 ms |
364 KB |
Output is correct |
102 |
Correct |
1 ms |
364 KB |
Output is correct |
103 |
Correct |
1 ms |
364 KB |
Output is correct |
104 |
Correct |
6 ms |
1260 KB |
Output is correct |
105 |
Correct |
13 ms |
2284 KB |
Output is correct |
106 |
Correct |
1 ms |
384 KB |
Output is correct |
107 |
Correct |
26 ms |
4076 KB |
Output is correct |
108 |
Correct |
38 ms |
5228 KB |
Output is correct |
109 |
Correct |
1 ms |
364 KB |
Output is correct |
110 |
Correct |
64 ms |
7152 KB |
Output is correct |
111 |
Correct |
66 ms |
8040 KB |
Output is correct |
112 |
Correct |
1 ms |
364 KB |
Output is correct |
113 |
Correct |
102 ms |
10092 KB |
Output is correct |
114 |
Execution timed out |
1084 ms |
6228 KB |
Time limit exceeded |
115 |
Halted |
0 ms |
0 KB |
- |