답안 #930586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930586 2024-02-20T07:26:10 Z AtabayRajabli 경주 (Race) (IOI11_race) C++17
21 / 100
25 ms 9812 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

const int sz = 1e3 + 5;
int t;
int dp[15][sz], in[sz], out[sz], d[sz], e[sz];
vector<array<int, 2>> g[sz];

void dfs(int v, int p)
{
    dp[0][v] = p;
    in[v] = ++t;
    for(auto i : g[v])
    {
        if(i[0] == p)continue;
        d[i[0]] = d[v] + i[1];
        e[i[0]] = e[v] + 1;
        dfs(i[0], v);
    }
    out[v] = ++t;
}

bool anc(int u, int v)
{
    return in[u] <= in[v] && out[v] <= out[u];
}

int lca(int u, int v)
{
    if(anc(u, v))return u;
    if(anc(v, u))return v;
    for(int i = 10; i >= 0; i--)
    {
        if(anc(dp[i][v], u))continue;
        v = dp[i][v];
    }
    return dp[0][v];
}

int dist(int u, int v)
{
    return d[u] + d[v] - d[lca(u, v)] * 2;
}

int len(int u, int v)
{
    return e[u] + e[v] - e[lca(u, v)] * 2;
}

int best_path(int n, int k, int h[][2], int l[])
{
    for(int i = 0; i < n; i++)
    {
        int u = ++h[i][0], v = ++h[i][1], w = l[i];
        g[u].pb({v, w});
        g[v].pb({u, w});
    }

    dfs(1, 0);

    for(int i = 1; i <= 10; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            dp[i][j] = dp[i - 1][dp[i - 1][j]];
        }
    }

    int mn = 1e9 + 10;
    for(int i = 1; i <= n; i++)
    {
        for(int j = i + 1; j <= n; j++)
        {
            if(dist(i, j) != k)continue;
            mn = min(mn, len(i, j));
        }
    }
    if(mn == 1e9 + 10)mn = -1;
    return mn;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2468 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2468 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 21 ms 2620 KB Output is correct
22 Correct 22 ms 2396 KB Output is correct
23 Correct 22 ms 2396 KB Output is correct
24 Correct 21 ms 2392 KB Output is correct
25 Correct 21 ms 2396 KB Output is correct
26 Correct 21 ms 2396 KB Output is correct
27 Correct 23 ms 2396 KB Output is correct
28 Correct 21 ms 2396 KB Output is correct
29 Correct 21 ms 2396 KB Output is correct
30 Correct 20 ms 2620 KB Output is correct
31 Correct 21 ms 2392 KB Output is correct
32 Correct 25 ms 2620 KB Output is correct
33 Correct 22 ms 2648 KB Output is correct
34 Correct 16 ms 2628 KB Output is correct
35 Correct 13 ms 2392 KB Output is correct
36 Correct 9 ms 2396 KB Output is correct
37 Correct 14 ms 2396 KB Output is correct
38 Correct 17 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2468 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Runtime error 23 ms 9812 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2468 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 21 ms 2620 KB Output is correct
22 Correct 22 ms 2396 KB Output is correct
23 Correct 22 ms 2396 KB Output is correct
24 Correct 21 ms 2392 KB Output is correct
25 Correct 21 ms 2396 KB Output is correct
26 Correct 21 ms 2396 KB Output is correct
27 Correct 23 ms 2396 KB Output is correct
28 Correct 21 ms 2396 KB Output is correct
29 Correct 21 ms 2396 KB Output is correct
30 Correct 20 ms 2620 KB Output is correct
31 Correct 21 ms 2392 KB Output is correct
32 Correct 25 ms 2620 KB Output is correct
33 Correct 22 ms 2648 KB Output is correct
34 Correct 16 ms 2628 KB Output is correct
35 Correct 13 ms 2392 KB Output is correct
36 Correct 9 ms 2396 KB Output is correct
37 Correct 14 ms 2396 KB Output is correct
38 Correct 17 ms 2392 KB Output is correct
39 Runtime error 23 ms 9812 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -