#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
int n, m, l;
pi par[100005];
vpi adj[100005];
bool vis[100005];
vi v;
pi dfs(int x, int p) {
vis[x] = 1;
pi res = pi(0, x);
for (auto it:adj[x]) if (it.f != p) {
par[it.f] = pi(x, it.s);
pi t = dfs(it.f, x);
res = max(res, pi(t.f + it.s, t.s));
}
return res;
}
int travelTime(int N, int M, int L, int a[], int b[], int c[]) {
n = N, m = M;
FOR(i, 0, m-1) {
adj[a[i]].pb(pi(b[i], c[i]));
adj[b[i]].pb(pi(a[i], c[i]));
}
if (m == n-1) return dfs(dfs(0, -1).s, -1).f;
FOR(i, 0, n-1) if (!vis[i]) {
int x = dfs(i, -1).s;
par[x] = pi(-1, -1);
auto [dist, y] = dfs(x, -1);
int best = dist, cur = 0;
while (par[y].f != -1) {
cur += par[y].s; y = par[y].f;
best = min(best, max(cur, dist-cur));
}
v.pb(best);
}
sort(all(v), greater<int>());
return max(v[0] + v[1] + L, v[1] + v[2] + 2 * L);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
64 ms |
13176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
64 ms |
13176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
64 ms |
13176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
6264 KB |
Output is correct |
2 |
Correct |
33 ms |
6264 KB |
Output is correct |
3 |
Correct |
36 ms |
6252 KB |
Output is correct |
4 |
Correct |
29 ms |
6264 KB |
Output is correct |
5 |
Correct |
29 ms |
6272 KB |
Output is correct |
6 |
Correct |
33 ms |
6648 KB |
Output is correct |
7 |
Correct |
30 ms |
6376 KB |
Output is correct |
8 |
Correct |
32 ms |
6144 KB |
Output is correct |
9 |
Correct |
29 ms |
6144 KB |
Output is correct |
10 |
Correct |
30 ms |
6400 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
8 ms |
4220 KB |
Output is correct |
13 |
Correct |
9 ms |
4348 KB |
Output is correct |
14 |
Correct |
8 ms |
4220 KB |
Output is correct |
15 |
Correct |
8 ms |
4220 KB |
Output is correct |
16 |
Correct |
8 ms |
4220 KB |
Output is correct |
17 |
Correct |
8 ms |
4092 KB |
Output is correct |
18 |
Correct |
8 ms |
4220 KB |
Output is correct |
19 |
Correct |
8 ms |
4220 KB |
Output is correct |
20 |
Correct |
2 ms |
2688 KB |
Output is correct |
21 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
64 ms |
13176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
64 ms |
13176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |