Submission #1051679

# Submission time Handle Problem Language Result Execution time Memory
1051679 2024-08-10T08:59:56 Z Nika533 Race (IOI11_race) C++17
100 / 100
720 ms 195928 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
using namespace std;

const int N=2e5+5;

int n,k,ans=1e9;
int depth[N];
long long d[N];
vector<pair<int,int>> g[N];
map<pair<int,int>,int> edge;
map<long long,long long> mymap[N];

void dfs(int x, int p) {
    d[x]=d[p]+edge[{x,p}]; depth[x]=depth[p]+1;
    mymap[x][d[x]]=depth[x];
    for (auto A:g[x]) {
        int y=A.f,w=A.s;
        if (y==p) continue;
        dfs(y,x);
        int sx=mymap[x].size(),sy=mymap[y].size();
        if (sx<sy) swap(mymap[x],mymap[y]);
        for (auto AA:mymap[y]) {
            long long D=AA.f;
            long long DEPTH=AA.s;
            if (DEPTH==0) continue;
            if (mymap[x][k+2*d[x]-D]>0) {
                int val=mymap[x][k+2*d[x]-D]+DEPTH-2*depth[x];
                ans=min(ans,val);
            }
        }
        for (auto AA:mymap[y]) {
            long long D=AA.f;
            long long DEPTH=AA.s;
            if (DEPTH==0) continue;
            if (mymap[x][D]==0) mymap[x][D]=DEPTH;
            else mymap[x][D]=min(mymap[x][D],DEPTH);
        }
    }
    // cout<<"X "<<x<<" "<<ans<<endl;
    // for (auto A:mymap[x]) {
    //     cout<<A.f<<" "<<A.s<<endl;
    // }
}

int best_path(int N, int K, int H[][2], int L[]) {
    n=N; k=K; edge[{0,0}]=1;
    for (int i=0; i<n-1; i++) {
        int a=H[i][1],b=H[i][0],c=L[i];
        g[a].pb({b,c}); g[b].pb({a,c});
        edge[{a,b}]=edge[{b,a}]=c;
    }
    dfs(0,0);
    if (ans==1000000000) ans=-1;
    return ans;
}

Compilation message

race.cpp: In function 'void dfs(int, int)':
race.cpp:20:19: warning: unused variable 'w' [-Wunused-variable]
   20 |         int y=A.f,w=A.s;
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 18780 KB Output is correct
2 Correct 2 ms 18780 KB Output is correct
3 Correct 2 ms 18780 KB Output is correct
4 Correct 2 ms 18780 KB Output is correct
5 Correct 2 ms 18780 KB Output is correct
6 Correct 2 ms 18780 KB Output is correct
7 Correct 2 ms 18780 KB Output is correct
8 Correct 2 ms 18780 KB Output is correct
9 Correct 2 ms 18780 KB Output is correct
10 Correct 2 ms 18780 KB Output is correct
11 Correct 2 ms 18780 KB Output is correct
12 Correct 2 ms 18780 KB Output is correct
13 Correct 2 ms 18780 KB Output is correct
14 Correct 2 ms 18964 KB Output is correct
15 Correct 2 ms 18780 KB Output is correct
16 Correct 2 ms 18780 KB Output is correct
17 Correct 2 ms 18780 KB Output is correct
18 Correct 2 ms 18780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 18780 KB Output is correct
2 Correct 2 ms 18780 KB Output is correct
3 Correct 2 ms 18780 KB Output is correct
4 Correct 2 ms 18780 KB Output is correct
5 Correct 2 ms 18780 KB Output is correct
6 Correct 2 ms 18780 KB Output is correct
7 Correct 2 ms 18780 KB Output is correct
8 Correct 2 ms 18780 KB Output is correct
9 Correct 2 ms 18780 KB Output is correct
10 Correct 2 ms 18780 KB Output is correct
11 Correct 2 ms 18780 KB Output is correct
12 Correct 2 ms 18780 KB Output is correct
13 Correct 2 ms 18780 KB Output is correct
14 Correct 2 ms 18964 KB Output is correct
15 Correct 2 ms 18780 KB Output is correct
16 Correct 2 ms 18780 KB Output is correct
17 Correct 2 ms 18780 KB Output is correct
18 Correct 2 ms 18780 KB Output is correct
19 Correct 2 ms 18876 KB Output is correct
20 Correct 2 ms 18780 KB Output is correct
21 Correct 3 ms 19292 KB Output is correct
22 Correct 4 ms 19548 KB Output is correct
23 Correct 4 ms 19292 KB Output is correct
24 Correct 4 ms 19292 KB Output is correct
25 Correct 3 ms 19292 KB Output is correct
26 Correct 4 ms 19288 KB Output is correct
27 Correct 3 ms 19032 KB Output is correct
28 Correct 4 ms 19292 KB Output is correct
29 Correct 3 ms 19292 KB Output is correct
30 Correct 5 ms 19292 KB Output is correct
31 Correct 4 ms 19292 KB Output is correct
32 Correct 4 ms 19292 KB Output is correct
33 Correct 4 ms 19548 KB Output is correct
34 Correct 3 ms 19288 KB Output is correct
35 Correct 3 ms 19288 KB Output is correct
36 Correct 3 ms 19288 KB Output is correct
37 Correct 4 ms 19292 KB Output is correct
38 Correct 3 ms 19288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 18780 KB Output is correct
2 Correct 2 ms 18780 KB Output is correct
3 Correct 2 ms 18780 KB Output is correct
4 Correct 2 ms 18780 KB Output is correct
5 Correct 2 ms 18780 KB Output is correct
6 Correct 2 ms 18780 KB Output is correct
7 Correct 2 ms 18780 KB Output is correct
8 Correct 2 ms 18780 KB Output is correct
9 Correct 2 ms 18780 KB Output is correct
10 Correct 2 ms 18780 KB Output is correct
11 Correct 2 ms 18780 KB Output is correct
12 Correct 2 ms 18780 KB Output is correct
13 Correct 2 ms 18780 KB Output is correct
14 Correct 2 ms 18964 KB Output is correct
15 Correct 2 ms 18780 KB Output is correct
16 Correct 2 ms 18780 KB Output is correct
17 Correct 2 ms 18780 KB Output is correct
18 Correct 2 ms 18780 KB Output is correct
19 Correct 154 ms 62544 KB Output is correct
20 Correct 198 ms 63780 KB Output is correct
21 Correct 220 ms 63580 KB Output is correct
22 Correct 211 ms 62460 KB Output is correct
23 Correct 313 ms 88264 KB Output is correct
24 Correct 218 ms 67924 KB Output is correct
25 Correct 188 ms 53848 KB Output is correct
26 Correct 74 ms 60500 KB Output is correct
27 Correct 379 ms 82472 KB Output is correct
28 Correct 439 ms 125928 KB Output is correct
29 Correct 435 ms 125176 KB Output is correct
30 Correct 292 ms 82656 KB Output is correct
31 Correct 351 ms 82512 KB Output is correct
32 Correct 442 ms 83796 KB Output is correct
33 Correct 374 ms 87376 KB Output is correct
34 Correct 570 ms 159220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 18780 KB Output is correct
2 Correct 2 ms 18780 KB Output is correct
3 Correct 2 ms 18780 KB Output is correct
4 Correct 2 ms 18780 KB Output is correct
5 Correct 2 ms 18780 KB Output is correct
6 Correct 2 ms 18780 KB Output is correct
7 Correct 2 ms 18780 KB Output is correct
8 Correct 2 ms 18780 KB Output is correct
9 Correct 2 ms 18780 KB Output is correct
10 Correct 2 ms 18780 KB Output is correct
11 Correct 2 ms 18780 KB Output is correct
12 Correct 2 ms 18780 KB Output is correct
13 Correct 2 ms 18780 KB Output is correct
14 Correct 2 ms 18964 KB Output is correct
15 Correct 2 ms 18780 KB Output is correct
16 Correct 2 ms 18780 KB Output is correct
17 Correct 2 ms 18780 KB Output is correct
18 Correct 2 ms 18780 KB Output is correct
19 Correct 2 ms 18876 KB Output is correct
20 Correct 2 ms 18780 KB Output is correct
21 Correct 3 ms 19292 KB Output is correct
22 Correct 4 ms 19548 KB Output is correct
23 Correct 4 ms 19292 KB Output is correct
24 Correct 4 ms 19292 KB Output is correct
25 Correct 3 ms 19292 KB Output is correct
26 Correct 4 ms 19288 KB Output is correct
27 Correct 3 ms 19032 KB Output is correct
28 Correct 4 ms 19292 KB Output is correct
29 Correct 3 ms 19292 KB Output is correct
30 Correct 5 ms 19292 KB Output is correct
31 Correct 4 ms 19292 KB Output is correct
32 Correct 4 ms 19292 KB Output is correct
33 Correct 4 ms 19548 KB Output is correct
34 Correct 3 ms 19288 KB Output is correct
35 Correct 3 ms 19288 KB Output is correct
36 Correct 3 ms 19288 KB Output is correct
37 Correct 4 ms 19292 KB Output is correct
38 Correct 3 ms 19288 KB Output is correct
39 Correct 154 ms 62544 KB Output is correct
40 Correct 198 ms 63780 KB Output is correct
41 Correct 220 ms 63580 KB Output is correct
42 Correct 211 ms 62460 KB Output is correct
43 Correct 313 ms 88264 KB Output is correct
44 Correct 218 ms 67924 KB Output is correct
45 Correct 188 ms 53848 KB Output is correct
46 Correct 74 ms 60500 KB Output is correct
47 Correct 379 ms 82472 KB Output is correct
48 Correct 439 ms 125928 KB Output is correct
49 Correct 435 ms 125176 KB Output is correct
50 Correct 292 ms 82656 KB Output is correct
51 Correct 351 ms 82512 KB Output is correct
52 Correct 442 ms 83796 KB Output is correct
53 Correct 374 ms 87376 KB Output is correct
54 Correct 570 ms 159220 KB Output is correct
55 Correct 21 ms 24912 KB Output is correct
56 Correct 12 ms 22620 KB Output is correct
57 Correct 100 ms 60224 KB Output is correct
58 Correct 74 ms 45252 KB Output is correct
59 Correct 107 ms 72784 KB Output is correct
60 Correct 432 ms 124968 KB Output is correct
61 Correct 318 ms 90076 KB Output is correct
62 Correct 266 ms 83780 KB Output is correct
63 Correct 408 ms 83792 KB Output is correct
64 Correct 700 ms 195928 KB Output is correct
65 Correct 720 ms 189564 KB Output is correct
66 Correct 426 ms 124500 KB Output is correct
67 Correct 322 ms 72124 KB Output is correct
68 Correct 613 ms 116340 KB Output is correct
69 Correct 668 ms 126144 KB Output is correct
70 Correct 550 ms 112212 KB Output is correct