답안 #988624

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988624 2024-05-25T10:16:04 Z HoriaHaivas 경주 (Race) (IOI11_race) C++14
100 / 100
593 ms 40020 KB
/*
    "care a facut teste cu Lattice reduction attack e ciudat"
    "linistiti va putin"
    - 2023 -
*/
#include<bits/stdc++.h>
#include "race.h"
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast")
#define int long long

using namespace std;

struct edge
{
    int to;
    int cost;
};

int n,k;
int ans;
bool blocked[200001];
int sz[200001];
int h[200001][2];
int l[200001];
vector<edge> nodes[200001];
int f[1000001];

void recalc(int node, int parent)
{
    sz[node]=1;
    for (auto x : nodes[node])
    {
        if (x.to!=parent && !blocked[x.to])
        {
            recalc(x.to,node);
            sz[node]+=sz[x.to];
        }
    }
}

int find_centroid(int compsize, int node, int parent)
{
    for (auto x : nodes[node])
    {
        if (x.to!=parent && !blocked[x.to] && sz[x.to]>compsize/2)
            return find_centroid(compsize,x.to,node);
    }
    return node;
}

void dfs(int node, int parent, int cost, int len)
{
    if (k<cost)
        return;
    ans=min(ans,len+f[k-cost]);
    for (auto x : nodes[node])
    {
        if (x.to!=parent && !blocked[x.to])
            dfs(x.to,node,cost+x.cost,len+1);
    }
}

void update(int node, int parent, int cost, int len)
{
    if (cost<=k)
    f[cost]=min(f[cost],len);
    for (auto x : nodes[node])
    {
        if (x.to!=parent && !blocked[x.to])
            update(x.to,node,cost+x.cost,len+1);
    }
}

void rem(int node, int parent, int cost)
{
    if (cost<=k)
    f[cost]=n+1;
    for (auto x : nodes[node])
    {
        if (x.to!=parent && !blocked[x.to])
            rem(x.to,node,cost+x.cost);
    }
}

void solve(int node)
{
    int c,i;
    recalc(node,-1);
    c=find_centroid(sz[node],node,-1);
    blocked[c]=1;
    f[0]=0;
    for (auto x : nodes[c])
    {
        if (!blocked[x.to])
        {
            dfs(x.to,c,x.cost,1);
            update(x.to,c,x.cost,1);
        }
    }
    for (auto x : nodes[c])
    {
        if (!blocked[x.to])
        {
            rem(x.to,c,x.cost);
        }
    }
    for (auto x : nodes[c])
    {
        if (!blocked[x.to])
        {
            solve(x.to);
        }
    }
}

signed best_path(signed N, signed K, signed H[][2], signed L[])
{
    int i,j,c,x,y;
    n=N;
    k=K;
    for (i=0;i<=k;i++)
         f[i]=n+1;
    for (i=0; i<n; i++)
    {
        x=H[i][0];
        y=H[i][1];
        x++;
        y++;
        c=L[i];
        nodes[x].push_back({y,c});
        nodes[y].push_back({x,c});
    }
    ans=n+1;
    solve(1);
    if (ans!=n+1)
        return ans;
    else
        return -1;
}

Compilation message

race.cpp: In function 'void solve(long long int)':
race.cpp:89:11: warning: unused variable 'i' [-Wunused-variable]
   89 |     int c,i;
      |           ^
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:120:11: warning: unused variable 'j' [-Wunused-variable]
  120 |     int i,j,c,x,y;
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12636 KB Output is correct
2 Correct 3 ms 12632 KB Output is correct
3 Correct 3 ms 12632 KB Output is correct
4 Correct 3 ms 12632 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 12636 KB Output is correct
8 Correct 3 ms 12636 KB Output is correct
9 Correct 4 ms 12636 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12720 KB Output is correct
12 Correct 3 ms 12636 KB Output is correct
13 Correct 3 ms 12636 KB Output is correct
14 Correct 3 ms 12632 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 3 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12636 KB Output is correct
2 Correct 3 ms 12632 KB Output is correct
3 Correct 3 ms 12632 KB Output is correct
4 Correct 3 ms 12632 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 12636 KB Output is correct
8 Correct 3 ms 12636 KB Output is correct
9 Correct 4 ms 12636 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12720 KB Output is correct
12 Correct 3 ms 12636 KB Output is correct
13 Correct 3 ms 12636 KB Output is correct
14 Correct 3 ms 12632 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 3 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 3 ms 12632 KB Output is correct
20 Correct 3 ms 12636 KB Output is correct
21 Correct 4 ms 12636 KB Output is correct
22 Correct 6 ms 18780 KB Output is correct
23 Correct 5 ms 18776 KB Output is correct
24 Correct 4 ms 18780 KB Output is correct
25 Correct 5 ms 18964 KB Output is correct
26 Correct 4 ms 16984 KB Output is correct
27 Correct 5 ms 18776 KB Output is correct
28 Correct 4 ms 14684 KB Output is correct
29 Correct 4 ms 16732 KB Output is correct
30 Correct 4 ms 16904 KB Output is correct
31 Correct 5 ms 18776 KB Output is correct
32 Correct 5 ms 18780 KB Output is correct
33 Correct 5 ms 18980 KB Output is correct
34 Correct 5 ms 18780 KB Output is correct
35 Correct 5 ms 18776 KB Output is correct
36 Correct 5 ms 18780 KB Output is correct
37 Correct 4 ms 18780 KB Output is correct
38 Correct 5 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12636 KB Output is correct
2 Correct 3 ms 12632 KB Output is correct
3 Correct 3 ms 12632 KB Output is correct
4 Correct 3 ms 12632 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 12636 KB Output is correct
8 Correct 3 ms 12636 KB Output is correct
9 Correct 4 ms 12636 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12720 KB Output is correct
12 Correct 3 ms 12636 KB Output is correct
13 Correct 3 ms 12636 KB Output is correct
14 Correct 3 ms 12632 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 3 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 126 ms 20040 KB Output is correct
20 Correct 128 ms 20048 KB Output is correct
21 Correct 116 ms 20044 KB Output is correct
22 Correct 110 ms 20108 KB Output is correct
23 Correct 70 ms 20316 KB Output is correct
24 Correct 49 ms 19544 KB Output is correct
25 Correct 106 ms 21332 KB Output is correct
26 Correct 72 ms 23120 KB Output is correct
27 Correct 197 ms 25684 KB Output is correct
28 Correct 305 ms 31600 KB Output is correct
29 Correct 462 ms 31004 KB Output is correct
30 Correct 150 ms 25684 KB Output is correct
31 Correct 164 ms 25680 KB Output is correct
32 Correct 284 ms 25712 KB Output is correct
33 Correct 215 ms 24400 KB Output is correct
34 Correct 208 ms 24404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12636 KB Output is correct
2 Correct 3 ms 12632 KB Output is correct
3 Correct 3 ms 12632 KB Output is correct
4 Correct 3 ms 12632 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 12636 KB Output is correct
8 Correct 3 ms 12636 KB Output is correct
9 Correct 4 ms 12636 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12720 KB Output is correct
12 Correct 3 ms 12636 KB Output is correct
13 Correct 3 ms 12636 KB Output is correct
14 Correct 3 ms 12632 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 3 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 3 ms 12632 KB Output is correct
20 Correct 3 ms 12636 KB Output is correct
21 Correct 4 ms 12636 KB Output is correct
22 Correct 6 ms 18780 KB Output is correct
23 Correct 5 ms 18776 KB Output is correct
24 Correct 4 ms 18780 KB Output is correct
25 Correct 5 ms 18964 KB Output is correct
26 Correct 4 ms 16984 KB Output is correct
27 Correct 5 ms 18776 KB Output is correct
28 Correct 4 ms 14684 KB Output is correct
29 Correct 4 ms 16732 KB Output is correct
30 Correct 4 ms 16904 KB Output is correct
31 Correct 5 ms 18776 KB Output is correct
32 Correct 5 ms 18780 KB Output is correct
33 Correct 5 ms 18980 KB Output is correct
34 Correct 5 ms 18780 KB Output is correct
35 Correct 5 ms 18776 KB Output is correct
36 Correct 5 ms 18780 KB Output is correct
37 Correct 4 ms 18780 KB Output is correct
38 Correct 5 ms 16732 KB Output is correct
39 Correct 126 ms 20040 KB Output is correct
40 Correct 128 ms 20048 KB Output is correct
41 Correct 116 ms 20044 KB Output is correct
42 Correct 110 ms 20108 KB Output is correct
43 Correct 70 ms 20316 KB Output is correct
44 Correct 49 ms 19544 KB Output is correct
45 Correct 106 ms 21332 KB Output is correct
46 Correct 72 ms 23120 KB Output is correct
47 Correct 197 ms 25684 KB Output is correct
48 Correct 305 ms 31600 KB Output is correct
49 Correct 462 ms 31004 KB Output is correct
50 Correct 150 ms 25684 KB Output is correct
51 Correct 164 ms 25680 KB Output is correct
52 Correct 284 ms 25712 KB Output is correct
53 Correct 215 ms 24400 KB Output is correct
54 Correct 208 ms 24404 KB Output is correct
55 Correct 10 ms 13144 KB Output is correct
56 Correct 12 ms 13400 KB Output is correct
57 Correct 58 ms 20544 KB Output is correct
58 Correct 30 ms 20684 KB Output is correct
59 Correct 75 ms 26708 KB Output is correct
60 Correct 353 ms 40020 KB Output is correct
61 Correct 159 ms 27172 KB Output is correct
62 Correct 172 ms 33992 KB Output is correct
63 Correct 295 ms 33960 KB Output is correct
64 Correct 593 ms 30240 KB Output is correct
65 Correct 347 ms 28240 KB Output is correct
66 Correct 382 ms 36204 KB Output is correct
67 Correct 89 ms 33984 KB Output is correct
68 Correct 274 ms 33764 KB Output is correct
69 Correct 264 ms 31260 KB Output is correct
70 Correct 257 ms 33872 KB Output is correct