#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
#define n 200005
#define pb push_back
#define f first
#define s second
#define pii pair<int, int>
int mn, dp[n], b[n], d[n];
bool f[n];
vector<pii> v[n];
void dfs(int u, int p)
{
f[u] = 1;
for(auto x : v[u])
if(x.f != p)
{
dfs(x.f, u);
if(dp[x.f] + x.s >= dp[u])
{
d[u] = dp[u];
b[u] = x.f;
dp[u] = dp[x.f] + x.s;
}
else d[u] = max(d[u], dp[x.f] + x.s);
}
}
void dfs1(int u, int p, int k)
{
if(k > dp[u]) b[u] = -1, dp[u] = k;
mn = min(mn, dp[u]);
for(auto x : v[u])
if(x.f != p)
{
if(b[u] == x.f) dfs1(x.f, u, max(d[u], k) + x.s);
else dfs1(x.f, u, dp[u] + x.s);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
int i;
vector<int> c;
for(i = 0; i < M; i++)
{
v[A[i]].pb({B[i], T[i]});
v[B[i]].pb({A[i], T[i]});
}
for(i = 0; i < N; i++)
if(!f[i])
{
dfs(i, -1);
mn = dp[i];
dfs1(i, -1, 0);
//cout << i << ' ' << mn << '\n';
c.pb(mn);
}
sort(c.rbegin(), c.rend());
if(c.size() == 1) return c[0];
if(c.size() == 2) return L + c[0] + c[1];
return max(c[0] + c[1] + L, 2 * L + c[1] + c[2]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
15168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
5012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
15168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
9224 KB |
Output is correct |
2 |
Correct |
15 ms |
9300 KB |
Output is correct |
3 |
Correct |
15 ms |
9304 KB |
Output is correct |
4 |
Correct |
15 ms |
9292 KB |
Output is correct |
5 |
Correct |
15 ms |
9252 KB |
Output is correct |
6 |
Correct |
16 ms |
9764 KB |
Output is correct |
7 |
Correct |
15 ms |
9512 KB |
Output is correct |
8 |
Correct |
14 ms |
9248 KB |
Output is correct |
9 |
Correct |
15 ms |
9168 KB |
Output is correct |
10 |
Correct |
15 ms |
9424 KB |
Output is correct |
11 |
Correct |
2 ms |
4924 KB |
Output is correct |
12 |
Correct |
5 ms |
6736 KB |
Output is correct |
13 |
Correct |
5 ms |
6864 KB |
Output is correct |
14 |
Correct |
5 ms |
6736 KB |
Output is correct |
15 |
Correct |
5 ms |
6736 KB |
Output is correct |
16 |
Correct |
7 ms |
6736 KB |
Output is correct |
17 |
Correct |
5 ms |
6284 KB |
Output is correct |
18 |
Correct |
5 ms |
6864 KB |
Output is correct |
19 |
Correct |
5 ms |
6672 KB |
Output is correct |
20 |
Correct |
2 ms |
5012 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
6 ms |
6736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
5012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
15168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |