답안 #957438

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957438 2024-04-03T17:13:58 Z Haidara314 경주 (Race) (IOI11_race) C++17
100 / 100
320 ms 78672 KB
#include "race.h"
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;
int ans=1e9;
int k;
vector<pair<int,int>>adj[200005];
ll dep[200005];
int dis[200005];
map<ll,int> dfs(int u,int p)
{
    map<ll,int>y;
    y[dep[u]]=dis[u];
    for(auto x:adj[u])
    {
        if(x.F!=p)
        {
            dep[x.F]=dep[u]+x.S;
            dis[x.F]=dis[u]+1;
            map<ll,int>j=dfs(x.F,u);
            if(j.size()>=y.size())
                swap(j,y);
            for(auto f:j)
            {
                if(f.F-dep[u]<=k&&y.count(k-f.F+2*dep[u]))
                {
                    ans=min(ans,y[k-f.F+2*dep[u]]+f.S-2*dis[u]);
                }
            }
            for(auto g:j)
            {
                if(y[g.F])
                y[g.F]=min(y[g.F],g.S);
                else
                    y[g.F]=g.S;
            }
        }
    }
    return y;
}
int best_path(int N, int K, int H[][2], int L[])
{
 k=K;
 for(int i=0;i<N-1;i++)
 {
     adj[H[i][0]].push_back({H[i][1],L[i]});
     adj[H[i][1]].push_back({H[i][0],L[i]});
 }
 dis[0]=1;
 dfs(0,-1);
  if(ans==1e9)
    ans=-1;
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 3 ms 11100 KB Output is correct
3 Correct 3 ms 11100 KB Output is correct
4 Correct 2 ms 11100 KB Output is correct
5 Correct 2 ms 11100 KB Output is correct
6 Correct 2 ms 11100 KB Output is correct
7 Correct 2 ms 11100 KB Output is correct
8 Correct 2 ms 11096 KB Output is correct
9 Correct 2 ms 11100 KB Output is correct
10 Correct 3 ms 11100 KB Output is correct
11 Correct 2 ms 11100 KB Output is correct
12 Correct 2 ms 11096 KB Output is correct
13 Correct 2 ms 11100 KB Output is correct
14 Correct 2 ms 11100 KB Output is correct
15 Correct 2 ms 11100 KB Output is correct
16 Correct 2 ms 11100 KB Output is correct
17 Correct 3 ms 11096 KB Output is correct
18 Correct 2 ms 11340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 3 ms 11100 KB Output is correct
3 Correct 3 ms 11100 KB Output is correct
4 Correct 2 ms 11100 KB Output is correct
5 Correct 2 ms 11100 KB Output is correct
6 Correct 2 ms 11100 KB Output is correct
7 Correct 2 ms 11100 KB Output is correct
8 Correct 2 ms 11096 KB Output is correct
9 Correct 2 ms 11100 KB Output is correct
10 Correct 3 ms 11100 KB Output is correct
11 Correct 2 ms 11100 KB Output is correct
12 Correct 2 ms 11096 KB Output is correct
13 Correct 2 ms 11100 KB Output is correct
14 Correct 2 ms 11100 KB Output is correct
15 Correct 2 ms 11100 KB Output is correct
16 Correct 2 ms 11100 KB Output is correct
17 Correct 3 ms 11096 KB Output is correct
18 Correct 2 ms 11340 KB Output is correct
19 Correct 2 ms 11100 KB Output is correct
20 Correct 3 ms 11100 KB Output is correct
21 Correct 3 ms 11100 KB Output is correct
22 Correct 3 ms 11100 KB Output is correct
23 Correct 3 ms 11100 KB Output is correct
24 Correct 3 ms 11100 KB Output is correct
25 Correct 3 ms 11096 KB Output is correct
26 Correct 3 ms 11100 KB Output is correct
27 Correct 2 ms 10936 KB Output is correct
28 Correct 3 ms 11100 KB Output is correct
29 Correct 3 ms 11100 KB Output is correct
30 Correct 3 ms 11100 KB Output is correct
31 Correct 3 ms 11100 KB Output is correct
32 Correct 3 ms 11100 KB Output is correct
33 Correct 3 ms 11100 KB Output is correct
34 Correct 2 ms 11100 KB Output is correct
35 Correct 3 ms 11100 KB Output is correct
36 Correct 3 ms 11100 KB Output is correct
37 Correct 3 ms 11100 KB Output is correct
38 Correct 3 ms 11100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 3 ms 11100 KB Output is correct
3 Correct 3 ms 11100 KB Output is correct
4 Correct 2 ms 11100 KB Output is correct
5 Correct 2 ms 11100 KB Output is correct
6 Correct 2 ms 11100 KB Output is correct
7 Correct 2 ms 11100 KB Output is correct
8 Correct 2 ms 11096 KB Output is correct
9 Correct 2 ms 11100 KB Output is correct
10 Correct 3 ms 11100 KB Output is correct
11 Correct 2 ms 11100 KB Output is correct
12 Correct 2 ms 11096 KB Output is correct
13 Correct 2 ms 11100 KB Output is correct
14 Correct 2 ms 11100 KB Output is correct
15 Correct 2 ms 11100 KB Output is correct
16 Correct 2 ms 11100 KB Output is correct
17 Correct 3 ms 11096 KB Output is correct
18 Correct 2 ms 11340 KB Output is correct
19 Correct 68 ms 16980 KB Output is correct
20 Correct 72 ms 17056 KB Output is correct
21 Correct 70 ms 16976 KB Output is correct
22 Correct 78 ms 17232 KB Output is correct
23 Correct 94 ms 17428 KB Output is correct
24 Correct 73 ms 17188 KB Output is correct
25 Correct 72 ms 32336 KB Output is correct
26 Correct 54 ms 46160 KB Output is correct
27 Correct 128 ms 21192 KB Output is correct
28 Correct 187 ms 78672 KB Output is correct
29 Correct 193 ms 76372 KB Output is correct
30 Correct 111 ms 21264 KB Output is correct
31 Correct 119 ms 21076 KB Output is correct
32 Correct 128 ms 21356 KB Output is correct
33 Correct 132 ms 20740 KB Output is correct
34 Correct 233 ms 33264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 3 ms 11100 KB Output is correct
3 Correct 3 ms 11100 KB Output is correct
4 Correct 2 ms 11100 KB Output is correct
5 Correct 2 ms 11100 KB Output is correct
6 Correct 2 ms 11100 KB Output is correct
7 Correct 2 ms 11100 KB Output is correct
8 Correct 2 ms 11096 KB Output is correct
9 Correct 2 ms 11100 KB Output is correct
10 Correct 3 ms 11100 KB Output is correct
11 Correct 2 ms 11100 KB Output is correct
12 Correct 2 ms 11096 KB Output is correct
13 Correct 2 ms 11100 KB Output is correct
14 Correct 2 ms 11100 KB Output is correct
15 Correct 2 ms 11100 KB Output is correct
16 Correct 2 ms 11100 KB Output is correct
17 Correct 3 ms 11096 KB Output is correct
18 Correct 2 ms 11340 KB Output is correct
19 Correct 2 ms 11100 KB Output is correct
20 Correct 3 ms 11100 KB Output is correct
21 Correct 3 ms 11100 KB Output is correct
22 Correct 3 ms 11100 KB Output is correct
23 Correct 3 ms 11100 KB Output is correct
24 Correct 3 ms 11100 KB Output is correct
25 Correct 3 ms 11096 KB Output is correct
26 Correct 3 ms 11100 KB Output is correct
27 Correct 2 ms 10936 KB Output is correct
28 Correct 3 ms 11100 KB Output is correct
29 Correct 3 ms 11100 KB Output is correct
30 Correct 3 ms 11100 KB Output is correct
31 Correct 3 ms 11100 KB Output is correct
32 Correct 3 ms 11100 KB Output is correct
33 Correct 3 ms 11100 KB Output is correct
34 Correct 2 ms 11100 KB Output is correct
35 Correct 3 ms 11100 KB Output is correct
36 Correct 3 ms 11100 KB Output is correct
37 Correct 3 ms 11100 KB Output is correct
38 Correct 3 ms 11100 KB Output is correct
39 Correct 68 ms 16980 KB Output is correct
40 Correct 72 ms 17056 KB Output is correct
41 Correct 70 ms 16976 KB Output is correct
42 Correct 78 ms 17232 KB Output is correct
43 Correct 94 ms 17428 KB Output is correct
44 Correct 73 ms 17188 KB Output is correct
45 Correct 72 ms 32336 KB Output is correct
46 Correct 54 ms 46160 KB Output is correct
47 Correct 128 ms 21192 KB Output is correct
48 Correct 187 ms 78672 KB Output is correct
49 Correct 193 ms 76372 KB Output is correct
50 Correct 111 ms 21264 KB Output is correct
51 Correct 119 ms 21076 KB Output is correct
52 Correct 128 ms 21356 KB Output is correct
53 Correct 132 ms 20740 KB Output is correct
54 Correct 233 ms 33264 KB Output is correct
55 Correct 12 ms 11868 KB Output is correct
56 Correct 7 ms 11356 KB Output is correct
57 Correct 46 ms 17244 KB Output is correct
58 Correct 36 ms 17100 KB Output is correct
59 Correct 74 ms 46200 KB Output is correct
60 Correct 190 ms 77392 KB Output is correct
61 Correct 144 ms 22892 KB Output is correct
62 Correct 121 ms 21140 KB Output is correct
63 Correct 130 ms 21332 KB Output is correct
64 Correct 320 ms 29200 KB Output is correct
65 Correct 310 ms 33488 KB Output is correct
66 Correct 208 ms 70404 KB Output is correct
67 Correct 92 ms 21184 KB Output is correct
68 Correct 223 ms 31772 KB Output is correct
69 Correct 272 ms 36528 KB Output is correct
70 Correct 206 ms 31004 KB Output is correct