#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
#define ff first
#define ss second
#define pb push_back
// constexpr int maxn = 1e4+10, inf = 0x3f3f3f3f;
constexpr int maxn = 1e5+10, inf = 0x3f3f3f3f;
vector<pii> g[maxn];
// pair<pii,pii> top[maxn];
bool mark[maxn];
int ans, diam;
// int dfs(int u, int p) {
// mark[u] = 1;
// for(pii pp : g[u]) {
// int v = pp.ff, w = pp.ss;
// if(v != p) {
// int val = dfs(v, u) + w;
// if(val > top[u].ff.ff) top[u].ss = top[u].ff, top[u].ff = {val, v};
// else if(val > top[u].ss.ff) top[u].ss = {val, v};
// }
// }
// diam = max(diam, top[u].ff.ff + top[u].ss.ff);
// return top[u].ff.ff;
// }
// void dfs2(int u, int p, int up) {
// ans = min(ans, max(top[u].ff.ff, up));
// // printf("%d %d\n", u, max(top[u].ff.ff, up));
// for(pii pp : g[u]) {
// int v = pp.ff, w = pp.ss;
// if(v != p)
// dfs2(v, u,w + max(up,
// (v != top[u].ff.ss?top[u].ff.ff:top[u].ss.ff)));
// }
// }
int brute(int u, int p) {
pii top = {0, 0};
for(pii pp : g[u]) {
int v = pp.ff, w = pp.ss;
if(v != p) {
int val = brute(v, u) + w;
if(val > top.ff) top.ss = top.ff, top.ff = val;
else if(val > top.ss) top.ss = val;
}
}
diam = max(diam, top.ff+top.ss);
return top.ff;
}
int tam[maxn];
void calc(int u, int p) {
mark[u] = 1;
ans = min(ans, tam[u]);
for(pii v : g[u])
if(v.ff != p)
calc(v.ff, u);
}
struct ANS
{
int a, b, c;
void upd(int x) {
if(x > a) c = b, b = a, a = x;
else if(x > b) c = b, b = x;
else if(x > c) c = x;
}
// void db() { printf("ans %d %d %d\n", a, b, c); }
inline int get(int x) { return max(a+b+x, b+c+2*x); }
} opa;
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int i = 0; i < M; i++)
g[A[i]].pb({B[i], T[i]}), g[B[i]].pb({A[i], T[i]});
// for(int i = 0; i < N; i++)
// if(!mark[i])
// ans = inf, dfs(i, -1), dfs2(i, -1, 0), opa.upd(ans);
for(int i = 0; i < N; i++)
tam[i] = brute(i, -1);
for(int i = 0; i < N; i++)
if(!mark[i])
ans = inf, calc(i, -1), opa.upd(ans);
// opa.db();
return max(opa.get(L), diam);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1101 ms |
13676 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1101 ms |
13676 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1101 ms |
13676 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
5484 KB |
Output is correct |
2 |
Correct |
27 ms |
5424 KB |
Output is correct |
3 |
Correct |
25 ms |
5484 KB |
Output is correct |
4 |
Correct |
22 ms |
5484 KB |
Output is correct |
5 |
Correct |
24 ms |
5484 KB |
Output is correct |
6 |
Correct |
41 ms |
5612 KB |
Output is correct |
7 |
Correct |
25 ms |
5612 KB |
Output is correct |
8 |
Correct |
21 ms |
5356 KB |
Output is correct |
9 |
Correct |
22 ms |
5356 KB |
Output is correct |
10 |
Correct |
24 ms |
5612 KB |
Output is correct |
11 |
Correct |
3 ms |
2668 KB |
Output is correct |
12 |
Correct |
3 ms |
3180 KB |
Output is correct |
13 |
Correct |
4 ms |
3180 KB |
Output is correct |
14 |
Correct |
4 ms |
3180 KB |
Output is correct |
15 |
Correct |
3 ms |
3180 KB |
Output is correct |
16 |
Correct |
3 ms |
3180 KB |
Output is correct |
17 |
Correct |
3 ms |
3180 KB |
Output is correct |
18 |
Correct |
4 ms |
3180 KB |
Output is correct |
19 |
Correct |
3 ms |
3180 KB |
Output is correct |
20 |
Incorrect |
2 ms |
2668 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1101 ms |
13676 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1101 ms |
13676 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |