#include <bits/stdc++.h>
#include "dreaming.h"
#define MAXN 100000
using namespace std;
vector<pair<int, int>> nodi[MAXN];
vector<bool> proc;
vector<int> dist;
void dfs(int v, vector<int>& gruppo)
{
proc[v] = true;
gruppo.push_back(v);
for (auto [u, w]: nodi[v])
{
if (!proc[u])
{
dist[u] = dist[v] + w;
dfs(u, gruppo);
}
}
}
void dfs2(int v)
{
proc[v] = true;
for (auto [u, w]: nodi[v])
{
if (!proc[u])
{
dist[u] = dist[v] + w;
dfs2(u);
}
}
}
bool dfs3(int v, int p, int y, vector<int>& diam)
{
if (v == y)
return true;
bool ok = false;
for (auto [u, w]: nodi[v])
{
if (u != p)
{
if (dfs3(u, v, y, diam))
{
ok = true;
diam.push_back(w);
break;
}
}
}
return ok;
}
vector<int> trova_diametro(int v)
{
vector<int> gruppo;
dist[v] = 0;
dfs(v, gruppo);
sort(gruppo.begin(), gruppo.end(), [&](int a, int b){return dist[a] > dist[b];});
for (int i: gruppo)
proc[i] = false;
int x, y;
x = gruppo[0];
dist[x] = 0;
dfs2(x);
sort(gruppo.begin(), gruppo.end(), [&](int a, int b){return dist[a] > dist[b];});
y = gruppo[0];
vector<int> diam;
dfs3(x, -1, y, diam);
return diam;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
for (int i = 0; i < M; i++)
{
nodi[A[i]].push_back({B[i], T[i]});
nodi[B[i]].push_back({A[i], T[i]});
}
vector<int> valori;
vector<int> diam;
dist.resize(N, 0);
proc.resize(N, false);
for (int i = 0; i < N; i++)
{
if (!proc[i])
{
vector<int> diametro = trova_diametro(i);
/*
cout << "\n\n";
for (int i: diametro)
cout << i << " ";
cout << "\n\n";
*/
if (diametro.empty())
{
valori.push_back(0);
diam.push_back(0);
continue;
}
int sx = 0, dx = 0;
for (int j: diametro)
dx += j;
int minimo = dx;
diam.push_back(dx);
for (int j = 0; j < diametro.size(); j++)
{
sx += diametro[j];
dx -= diametro[j];
minimo = min(minimo, max(sx, dx));
}
valori.push_back(minimo);
}
}
sort(valori.begin(), valori.end());
sort(diam.begin(), diam.end());
return max(diam.back(), valori.back() + valori[valori.size() - 2] + L);
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:130:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
130 | for (int j = 0; j < diametro.size(); j++)
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
16568 KB |
Output is correct |
2 |
Correct |
64 ms |
16716 KB |
Output is correct |
3 |
Correct |
38 ms |
11764 KB |
Output is correct |
4 |
Correct |
8 ms |
4812 KB |
Output is correct |
5 |
Correct |
7 ms |
3788 KB |
Output is correct |
6 |
Correct |
13 ms |
5836 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
25 ms |
7248 KB |
Output is correct |
9 |
Correct |
31 ms |
9400 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
49 ms |
11068 KB |
Output is correct |
12 |
Correct |
68 ms |
14040 KB |
Output is correct |
13 |
Correct |
2 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
1 ms |
2636 KB |
Output is correct |
4 |
Correct |
1 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 |
2652 KB |
Output is correct |
12 |
Correct |
1 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 |
1 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 |
1 ms |
2636 KB |
Output is correct |
19 |
Correct |
1 ms |
2636 KB |
Output is correct |
20 |
Correct |
1 ms |
2636 KB |
Output is correct |
21 |
Correct |
1 ms |
2636 KB |
Output is correct |
22 |
Correct |
1 ms |
2636 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2636 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
16568 KB |
Output is correct |
2 |
Correct |
64 ms |
16716 KB |
Output is correct |
3 |
Correct |
38 ms |
11764 KB |
Output is correct |
4 |
Correct |
8 ms |
4812 KB |
Output is correct |
5 |
Correct |
7 ms |
3788 KB |
Output is correct |
6 |
Correct |
13 ms |
5836 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
25 ms |
7248 KB |
Output is correct |
9 |
Correct |
31 ms |
9400 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
49 ms |
11068 KB |
Output is correct |
12 |
Correct |
68 ms |
14040 KB |
Output is correct |
13 |
Correct |
2 ms |
2764 KB |
Output is correct |
14 |
Correct |
1 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
1 ms |
2636 KB |
Output is correct |
17 |
Correct |
1 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 |
2652 KB |
Output is correct |
25 |
Correct |
1 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 |
1 ms |
2636 KB |
Output is correct |
29 |
Correct |
2 ms |
2636 KB |
Output is correct |
30 |
Correct |
2 ms |
2636 KB |
Output is correct |
31 |
Correct |
1 ms |
2636 KB |
Output is correct |
32 |
Correct |
1 ms |
2636 KB |
Output is correct |
33 |
Correct |
1 ms |
2636 KB |
Output is correct |
34 |
Correct |
1 ms |
2636 KB |
Output is correct |
35 |
Correct |
1 ms |
2636 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2636 KB |
Output is correct |
38 |
Correct |
1 ms |
2648 KB |
Output is correct |
39 |
Correct |
54 ms |
16732 KB |
Output is correct |
40 |
Correct |
56 ms |
16636 KB |
Output is correct |
41 |
Correct |
37 ms |
11712 KB |
Output is correct |
42 |
Correct |
9 ms |
4812 KB |
Output is correct |
43 |
Correct |
1 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 |
3 ms |
2636 KB |
Output is correct |
47 |
Correct |
1 ms |
2636 KB |
Output is correct |
48 |
Correct |
1 ms |
2636 KB |
Output is correct |
49 |
Correct |
1 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 |
1 ms |
2636 KB |
Output is correct |
53 |
Correct |
2 ms |
2636 KB |
Output is correct |
54 |
Correct |
1 ms |
2648 KB |
Output is correct |
55 |
Correct |
1 ms |
2636 KB |
Output is correct |
56 |
Correct |
1 ms |
2636 KB |
Output is correct |
57 |
Correct |
59 ms |
8900 KB |
Output is correct |
58 |
Correct |
60 ms |
8716 KB |
Output is correct |
59 |
Correct |
63 ms |
8896 KB |
Output is correct |
60 |
Correct |
64 ms |
8700 KB |
Output is correct |
61 |
Correct |
79 ms |
8712 KB |
Output is correct |
62 |
Correct |
65 ms |
8592 KB |
Output is correct |
63 |
Correct |
55 ms |
8648 KB |
Output is correct |
64 |
Correct |
70 ms |
8664 KB |
Output is correct |
65 |
Correct |
77 ms |
8620 KB |
Output is correct |
66 |
Correct |
64 ms |
8556 KB |
Output is correct |
67 |
Correct |
64 ms |
8800 KB |
Output is correct |
68 |
Correct |
69 ms |
8868 KB |
Output is correct |
69 |
Correct |
71 ms |
8744 KB |
Output is correct |
70 |
Correct |
68 ms |
8668 KB |
Output is correct |
71 |
Correct |
1 ms |
2636 KB |
Output is correct |
72 |
Correct |
3 ms |
2792 KB |
Output is correct |
73 |
Correct |
3 ms |
2788 KB |
Output is correct |
74 |
Correct |
3 ms |
2764 KB |
Output is correct |
75 |
Correct |
3 ms |
2764 KB |
Output is correct |
76 |
Correct |
3 ms |
2764 KB |
Output is correct |
77 |
Correct |
3 ms |
2764 KB |
Output is correct |
78 |
Correct |
3 ms |
2764 KB |
Output is correct |
79 |
Correct |
3 ms |
2892 KB |
Output is correct |
80 |
Correct |
72 ms |
8840 KB |
Output is correct |
81 |
Correct |
63 ms |
8768 KB |
Output is correct |
82 |
Correct |
64 ms |
8744 KB |
Output is correct |
83 |
Correct |
65 ms |
8796 KB |
Output is correct |
84 |
Correct |
2 ms |
2764 KB |
Output is correct |
85 |
Correct |
2 ms |
2764 KB |
Output is correct |
86 |
Correct |
3 ms |
2764 KB |
Output is correct |
87 |
Correct |
3 ms |
2792 KB |
Output is correct |
88 |
Correct |
2 ms |
2764 KB |
Output is correct |
89 |
Correct |
2 ms |
2792 KB |
Output is correct |
90 |
Correct |
2 ms |
2792 KB |
Output is correct |
91 |
Correct |
3 ms |
2820 KB |
Output is correct |
92 |
Correct |
3 ms |
2764 KB |
Output is correct |
93 |
Correct |
3 ms |
2764 KB |
Output is correct |
94 |
Correct |
1 ms |
2636 KB |
Output is correct |
95 |
Correct |
1 ms |
2636 KB |
Output is correct |
96 |
Correct |
1 ms |
2636 KB |
Output is correct |
97 |
Correct |
1 ms |
2636 KB |
Output is correct |
98 |
Correct |
2 ms |
2636 KB |
Output is correct |
99 |
Correct |
2 ms |
2636 KB |
Output is correct |
100 |
Correct |
1 ms |
2636 KB |
Output is correct |
101 |
Correct |
2 ms |
2636 KB |
Output is correct |
102 |
Correct |
2 ms |
2636 KB |
Output is correct |
103 |
Correct |
1 ms |
2636 KB |
Output is correct |
104 |
Correct |
7 ms |
3788 KB |
Output is correct |
105 |
Correct |
14 ms |
5852 KB |
Output is correct |
106 |
Correct |
1 ms |
2636 KB |
Output is correct |
107 |
Correct |
24 ms |
7172 KB |
Output is correct |
108 |
Correct |
29 ms |
9408 KB |
Output is correct |
109 |
Correct |
2 ms |
2636 KB |
Output is correct |
110 |
Correct |
51 ms |
11068 KB |
Output is correct |
111 |
Correct |
68 ms |
14012 KB |
Output is correct |
112 |
Correct |
2 ms |
2764 KB |
Output is correct |
113 |
Correct |
77 ms |
17988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
5960 KB |
Output is correct |
2 |
Incorrect |
23 ms |
6088 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
1 ms |
2636 KB |
Output is correct |
4 |
Correct |
1 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 |
2652 KB |
Output is correct |
12 |
Correct |
1 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 |
1 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 |
1 ms |
2636 KB |
Output is correct |
19 |
Correct |
1 ms |
2636 KB |
Output is correct |
20 |
Correct |
1 ms |
2636 KB |
Output is correct |
21 |
Correct |
1 ms |
2636 KB |
Output is correct |
22 |
Correct |
1 ms |
2636 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2636 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
2 ms |
2636 KB |
Output is correct |
27 |
Correct |
2 ms |
2736 KB |
Output is correct |
28 |
Correct |
3 ms |
2764 KB |
Output is correct |
29 |
Correct |
2 ms |
2724 KB |
Output is correct |
30 |
Correct |
2 ms |
2764 KB |
Output is correct |
31 |
Correct |
3 ms |
2764 KB |
Output is correct |
32 |
Incorrect |
2 ms |
2656 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
16568 KB |
Output is correct |
2 |
Correct |
64 ms |
16716 KB |
Output is correct |
3 |
Correct |
38 ms |
11764 KB |
Output is correct |
4 |
Correct |
8 ms |
4812 KB |
Output is correct |
5 |
Correct |
7 ms |
3788 KB |
Output is correct |
6 |
Correct |
13 ms |
5836 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
25 ms |
7248 KB |
Output is correct |
9 |
Correct |
31 ms |
9400 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
49 ms |
11068 KB |
Output is correct |
12 |
Correct |
68 ms |
14040 KB |
Output is correct |
13 |
Correct |
2 ms |
2764 KB |
Output is correct |
14 |
Correct |
1 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
1 ms |
2636 KB |
Output is correct |
17 |
Correct |
1 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 |
2652 KB |
Output is correct |
25 |
Correct |
1 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 |
1 ms |
2636 KB |
Output is correct |
29 |
Correct |
2 ms |
2636 KB |
Output is correct |
30 |
Correct |
2 ms |
2636 KB |
Output is correct |
31 |
Correct |
1 ms |
2636 KB |
Output is correct |
32 |
Correct |
1 ms |
2636 KB |
Output is correct |
33 |
Correct |
1 ms |
2636 KB |
Output is correct |
34 |
Correct |
1 ms |
2636 KB |
Output is correct |
35 |
Correct |
1 ms |
2636 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2636 KB |
Output is correct |
38 |
Correct |
1 ms |
2648 KB |
Output is correct |
39 |
Correct |
54 ms |
16732 KB |
Output is correct |
40 |
Correct |
56 ms |
16636 KB |
Output is correct |
41 |
Correct |
37 ms |
11712 KB |
Output is correct |
42 |
Correct |
9 ms |
4812 KB |
Output is correct |
43 |
Correct |
1 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 |
3 ms |
2636 KB |
Output is correct |
47 |
Correct |
1 ms |
2636 KB |
Output is correct |
48 |
Correct |
1 ms |
2636 KB |
Output is correct |
49 |
Correct |
1 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 |
1 ms |
2636 KB |
Output is correct |
53 |
Correct |
2 ms |
2636 KB |
Output is correct |
54 |
Correct |
1 ms |
2648 KB |
Output is correct |
55 |
Correct |
1 ms |
2636 KB |
Output is correct |
56 |
Correct |
1 ms |
2636 KB |
Output is correct |
57 |
Correct |
59 ms |
8900 KB |
Output is correct |
58 |
Correct |
60 ms |
8716 KB |
Output is correct |
59 |
Correct |
63 ms |
8896 KB |
Output is correct |
60 |
Correct |
64 ms |
8700 KB |
Output is correct |
61 |
Correct |
79 ms |
8712 KB |
Output is correct |
62 |
Correct |
65 ms |
8592 KB |
Output is correct |
63 |
Correct |
55 ms |
8648 KB |
Output is correct |
64 |
Correct |
70 ms |
8664 KB |
Output is correct |
65 |
Correct |
77 ms |
8620 KB |
Output is correct |
66 |
Correct |
64 ms |
8556 KB |
Output is correct |
67 |
Correct |
64 ms |
8800 KB |
Output is correct |
68 |
Correct |
69 ms |
8868 KB |
Output is correct |
69 |
Correct |
71 ms |
8744 KB |
Output is correct |
70 |
Correct |
68 ms |
8668 KB |
Output is correct |
71 |
Correct |
1 ms |
2636 KB |
Output is correct |
72 |
Correct |
3 ms |
2792 KB |
Output is correct |
73 |
Correct |
3 ms |
2788 KB |
Output is correct |
74 |
Correct |
3 ms |
2764 KB |
Output is correct |
75 |
Correct |
3 ms |
2764 KB |
Output is correct |
76 |
Correct |
3 ms |
2764 KB |
Output is correct |
77 |
Correct |
3 ms |
2764 KB |
Output is correct |
78 |
Correct |
3 ms |
2764 KB |
Output is correct |
79 |
Correct |
3 ms |
2892 KB |
Output is correct |
80 |
Correct |
72 ms |
8840 KB |
Output is correct |
81 |
Correct |
63 ms |
8768 KB |
Output is correct |
82 |
Correct |
64 ms |
8744 KB |
Output is correct |
83 |
Correct |
65 ms |
8796 KB |
Output is correct |
84 |
Correct |
2 ms |
2764 KB |
Output is correct |
85 |
Correct |
2 ms |
2764 KB |
Output is correct |
86 |
Correct |
3 ms |
2764 KB |
Output is correct |
87 |
Correct |
3 ms |
2792 KB |
Output is correct |
88 |
Correct |
2 ms |
2764 KB |
Output is correct |
89 |
Correct |
2 ms |
2792 KB |
Output is correct |
90 |
Correct |
2 ms |
2792 KB |
Output is correct |
91 |
Correct |
3 ms |
2820 KB |
Output is correct |
92 |
Correct |
3 ms |
2764 KB |
Output is correct |
93 |
Correct |
3 ms |
2764 KB |
Output is correct |
94 |
Correct |
1 ms |
2636 KB |
Output is correct |
95 |
Correct |
1 ms |
2636 KB |
Output is correct |
96 |
Correct |
1 ms |
2636 KB |
Output is correct |
97 |
Correct |
1 ms |
2636 KB |
Output is correct |
98 |
Correct |
2 ms |
2636 KB |
Output is correct |
99 |
Correct |
2 ms |
2636 KB |
Output is correct |
100 |
Correct |
1 ms |
2636 KB |
Output is correct |
101 |
Correct |
2 ms |
2636 KB |
Output is correct |
102 |
Correct |
2 ms |
2636 KB |
Output is correct |
103 |
Correct |
1 ms |
2636 KB |
Output is correct |
104 |
Correct |
7 ms |
3788 KB |
Output is correct |
105 |
Correct |
14 ms |
5852 KB |
Output is correct |
106 |
Correct |
1 ms |
2636 KB |
Output is correct |
107 |
Correct |
24 ms |
7172 KB |
Output is correct |
108 |
Correct |
29 ms |
9408 KB |
Output is correct |
109 |
Correct |
2 ms |
2636 KB |
Output is correct |
110 |
Correct |
51 ms |
11068 KB |
Output is correct |
111 |
Correct |
68 ms |
14012 KB |
Output is correct |
112 |
Correct |
2 ms |
2764 KB |
Output is correct |
113 |
Correct |
77 ms |
17988 KB |
Output is correct |
114 |
Correct |
23 ms |
5960 KB |
Output is correct |
115 |
Incorrect |
23 ms |
6088 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |