#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5, logn = 18, inf = 1e9 + 5;
struct edge { int t, w; };
vector<vector<edge> > g(maxn);
bool cmp(edge a, edge b) { return a.w < b.w; }
int n, m;
vector<vector<int> > l(logn, vector<int>(maxn, 0)), mx(logn, vector<int>(maxn, 0));
vector<int> d(maxn, 0), cr(maxn, inf);
int lca(int u, int v)
{
if (d[u] < d[v]) swap(u, v); // u je hlbsie
int ans = 0;
for (int i = logn - 1; i >= 0; i--) if ((1 << i) & (d[u] - d[v])) ans = max(ans, mx[i][u]), u = l[i][u];
if (u == v) return ans;
for (int i = logn - 1; i >= 0; i--) if(l[i][u] != l[i][v])
{
ans = max({ans, mx[i][u], mx[i][v]});
u = l[i][u], v = l[i][v];
}
return max({ans, mx[0][u], mx[0][v]});
}
set<pair<int, int> > s;
void dfs(int u, int p = -1)
{
sort(g[u].begin(), g[u].end(), cmp);
if (g[u].size() >= 3)
s.insert({ g[u][2].w, u});
for (int i = 1; i < logn; i++) l[i][u] = l[i-1][l[i-1][u]], mx[i][u] = max(mx[i-1][u], mx[i-1][l[i-1][u]]);
for (const edge &i : g[u])
{
if (i.t == p) continue;
l[0][i.t] = u, mx[0][i.t] = i.w, d[i.t] = d[u] + 1;
dfs(i.t, u);
}
}
void init(int N, int M, vector<int> u, vector<int> v, vector<int> w)
{
n = N, m = M;
for (int i =0;i<m;i++) g[u[i]].push_back({v[i], w[i]}), g[v[i]].push_back({u[i], w[i]});
dfs(0, -1);
while (!s.empty())
{
int d = s.begin()->first, u = s.begin()->second;
s.erase(s.begin());
if (cr[u] < inf) continue;
cr[u] = d;
for (edge i : g[u])
if (cr[i.t] == inf)
s.insert({max(d, i.w), i.t});
}
}
int getMinimumFuelCapacity(int x, int y) {
int ans = max(lca(x, y), min(cr[x], cr[y]));
return ans == inf ? -1 : ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
17476 KB |
Output is correct |
2 |
Correct |
11 ms |
17460 KB |
Output is correct |
3 |
Correct |
10 ms |
17452 KB |
Output is correct |
4 |
Correct |
11 ms |
17604 KB |
Output is correct |
5 |
Correct |
11 ms |
17584 KB |
Output is correct |
6 |
Correct |
11 ms |
17552 KB |
Output is correct |
7 |
Correct |
11 ms |
17568 KB |
Output is correct |
8 |
Correct |
11 ms |
17604 KB |
Output is correct |
9 |
Correct |
153 ms |
27184 KB |
Output is correct |
10 |
Correct |
170 ms |
30696 KB |
Output is correct |
11 |
Correct |
167 ms |
29932 KB |
Output is correct |
12 |
Correct |
177 ms |
30968 KB |
Output is correct |
13 |
Correct |
180 ms |
33124 KB |
Output is correct |
14 |
Correct |
169 ms |
26624 KB |
Output is correct |
15 |
Correct |
453 ms |
33440 KB |
Output is correct |
16 |
Correct |
450 ms |
31256 KB |
Output is correct |
17 |
Correct |
435 ms |
36136 KB |
Output is correct |
18 |
Correct |
482 ms |
34492 KB |
Output is correct |
19 |
Execution timed out |
2062 ms |
435256 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
17476 KB |
Output is correct |
2 |
Correct |
11 ms |
17460 KB |
Output is correct |
3 |
Correct |
283 ms |
30804 KB |
Output is correct |
4 |
Correct |
345 ms |
30776 KB |
Output is correct |
5 |
Correct |
296 ms |
30520 KB |
Output is correct |
6 |
Correct |
294 ms |
30648 KB |
Output is correct |
7 |
Correct |
291 ms |
30648 KB |
Output is correct |
8 |
Correct |
314 ms |
30088 KB |
Output is correct |
9 |
Correct |
304 ms |
30488 KB |
Output is correct |
10 |
Correct |
277 ms |
30072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
17476 KB |
Output is correct |
2 |
Correct |
11 ms |
17460 KB |
Output is correct |
3 |
Correct |
10 ms |
17452 KB |
Output is correct |
4 |
Correct |
11 ms |
17604 KB |
Output is correct |
5 |
Correct |
11 ms |
17584 KB |
Output is correct |
6 |
Correct |
11 ms |
17552 KB |
Output is correct |
7 |
Correct |
11 ms |
17568 KB |
Output is correct |
8 |
Correct |
11 ms |
17604 KB |
Output is correct |
9 |
Runtime error |
1225 ms |
524292 KB |
Execution killed with signal 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1225 ms |
524292 KB |
Execution killed with signal 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
17476 KB |
Output is correct |
2 |
Correct |
11 ms |
17460 KB |
Output is correct |
3 |
Correct |
10 ms |
17452 KB |
Output is correct |
4 |
Correct |
11 ms |
17604 KB |
Output is correct |
5 |
Correct |
11 ms |
17584 KB |
Output is correct |
6 |
Correct |
11 ms |
17552 KB |
Output is correct |
7 |
Correct |
11 ms |
17568 KB |
Output is correct |
8 |
Correct |
11 ms |
17604 KB |
Output is correct |
9 |
Correct |
153 ms |
27184 KB |
Output is correct |
10 |
Correct |
170 ms |
30696 KB |
Output is correct |
11 |
Correct |
167 ms |
29932 KB |
Output is correct |
12 |
Correct |
177 ms |
30968 KB |
Output is correct |
13 |
Correct |
180 ms |
33124 KB |
Output is correct |
14 |
Correct |
169 ms |
26624 KB |
Output is correct |
15 |
Correct |
453 ms |
33440 KB |
Output is correct |
16 |
Correct |
450 ms |
31256 KB |
Output is correct |
17 |
Correct |
435 ms |
36136 KB |
Output is correct |
18 |
Correct |
482 ms |
34492 KB |
Output is correct |
19 |
Correct |
283 ms |
30804 KB |
Output is correct |
20 |
Correct |
345 ms |
30776 KB |
Output is correct |
21 |
Correct |
296 ms |
30520 KB |
Output is correct |
22 |
Correct |
294 ms |
30648 KB |
Output is correct |
23 |
Correct |
291 ms |
30648 KB |
Output is correct |
24 |
Correct |
314 ms |
30088 KB |
Output is correct |
25 |
Correct |
304 ms |
30488 KB |
Output is correct |
26 |
Correct |
277 ms |
30072 KB |
Output is correct |
27 |
Correct |
13 ms |
17532 KB |
Output is correct |
28 |
Correct |
10 ms |
17604 KB |
Output is correct |
29 |
Correct |
12 ms |
17560 KB |
Output is correct |
30 |
Correct |
11 ms |
17612 KB |
Output is correct |
31 |
Correct |
12 ms |
17560 KB |
Output is correct |
32 |
Correct |
11 ms |
17552 KB |
Output is correct |
33 |
Correct |
11 ms |
17564 KB |
Output is correct |
34 |
Correct |
11 ms |
17660 KB |
Output is correct |
35 |
Correct |
11 ms |
17600 KB |
Output is correct |
36 |
Correct |
26 ms |
18968 KB |
Output is correct |
37 |
Correct |
182 ms |
31236 KB |
Output is correct |
38 |
Correct |
185 ms |
28324 KB |
Output is correct |
39 |
Correct |
166 ms |
25868 KB |
Output is correct |
40 |
Correct |
161 ms |
25408 KB |
Output is correct |
41 |
Correct |
156 ms |
25208 KB |
Output is correct |
42 |
Correct |
152 ms |
25244 KB |
Output is correct |
43 |
Correct |
186 ms |
29436 KB |
Output is correct |
44 |
Correct |
193 ms |
30464 KB |
Output is correct |
45 |
Correct |
183 ms |
31936 KB |
Output is correct |
46 |
Correct |
190 ms |
27304 KB |
Output is correct |
47 |
Correct |
41 ms |
19220 KB |
Output is correct |
48 |
Correct |
476 ms |
34276 KB |
Output is correct |
49 |
Correct |
493 ms |
32400 KB |
Output is correct |
50 |
Correct |
466 ms |
31292 KB |
Output is correct |
51 |
Correct |
445 ms |
30692 KB |
Output is correct |
52 |
Correct |
414 ms |
30068 KB |
Output is correct |
53 |
Correct |
299 ms |
30684 KB |
Output is correct |
54 |
Correct |
519 ms |
34304 KB |
Output is correct |
55 |
Correct |
457 ms |
35004 KB |
Output is correct |
56 |
Correct |
440 ms |
38000 KB |
Output is correct |
57 |
Correct |
411 ms |
33212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1225 ms |
524292 KB |
Execution killed with signal 9 |