// M
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
const int N = 100005;
int n, m, L, D[3][N], M[N];
vector < pair < int , int > > Adj[N];
vector < int > vec;
void DFS(int v, int p, int w)
{
M[v] = 1;
if (w == 0)
vec.push_back(v);
for (auto u : Adj[v])
if (u.first != p)
D[w][u.first] = D[w][v] + u.second, DFS(u.first, v, w);
}
int travelTime(int _n, int _m, int _L, int * A, int * B, int * W)
{
n = _n; m = _m; L = _L;
for (int i = 0; i < m; i ++)
{
Adj[A[i]].push_back({B[i], W[i]});
Adj[B[i]].push_back({A[i], W[i]});
}
vector < int > V;
for (int i = 0; i < n; i ++)
if (!M[i])
{
vec.clear();
DFS(i, -1, 0);
int d1 = i;
for (int v : vec)
if (D[0][v] > D[0][d1])
d1 = v;
DFS(d1, -1, 1);
int d2 = i;
for (int v : vec)
if (D[1][v] > D[1][d2])
d2 = v;
DFS(d2, -1, 2);
int Mn = D[1][d2];
for (int v : vec)
Mn = min(Mn, max(D[1][v], D[2][v]));
V.push_back(Mn);
}
sort(V.begin(), V.end());
reverse(V.begin(), V.end());
int Mx = V[0];
if ((int)V.size() > 1)
Mx = max(Mx, V[0] + V[1] + L);
if ((int)V.size() > 2)
Mx = max(Mx, V[1] + V[2] + L * 2);
return Mx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
68 ms |
15476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
68 ms |
15476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
68 ms |
15476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
7284 KB |
Output is correct |
2 |
Correct |
46 ms |
7288 KB |
Output is correct |
3 |
Correct |
39 ms |
7288 KB |
Output is correct |
4 |
Correct |
32 ms |
7288 KB |
Output is correct |
5 |
Correct |
39 ms |
7288 KB |
Output is correct |
6 |
Correct |
44 ms |
7800 KB |
Output is correct |
7 |
Correct |
40 ms |
7520 KB |
Output is correct |
8 |
Correct |
36 ms |
7160 KB |
Output is correct |
9 |
Correct |
37 ms |
7156 KB |
Output is correct |
10 |
Correct |
39 ms |
7420 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
8 ms |
4604 KB |
Output is correct |
13 |
Correct |
8 ms |
4732 KB |
Output is correct |
14 |
Correct |
8 ms |
4604 KB |
Output is correct |
15 |
Correct |
8 ms |
4604 KB |
Output is correct |
16 |
Correct |
8 ms |
4604 KB |
Output is correct |
17 |
Correct |
7 ms |
3964 KB |
Output is correct |
18 |
Correct |
10 ms |
4732 KB |
Output is correct |
19 |
Correct |
8 ms |
4604 KB |
Output is correct |
20 |
Correct |
3 ms |
2688 KB |
Output is correct |
21 |
Correct |
2 ms |
2688 KB |
Output is correct |
22 |
Correct |
2 ms |
2816 KB |
Output is correct |
23 |
Correct |
7 ms |
4604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
68 ms |
15476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
68 ms |
15476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |