Submission #1051629

# Submission time Handle Problem Language Result Execution time Memory
1051629 2024-08-10T08:43:29 Z Nika533 Race (IOI11_race) C++17
9 / 100
221 ms 70052 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,int> 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;
            int DEPTH=AA.s;
            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;
            int DEPTH=AA.s;
            if (mymap[x][D]==0) mymap[x][D]=DEPTH;
            else mymap[x][D]=min(mymap[x][D],DEPTH);
        }
    }
}

int best_path(int N, int K, int H[][2], int L[]) {
    n=N; k=K;
    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 18776 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 18952 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 3 ms 18780 KB Output is correct
10 Correct 2 ms 18780 KB Output is correct
11 Correct 3 ms 18780 KB Output is correct
12 Correct 2 ms 18912 KB Output is correct
13 Correct 2 ms 18780 KB Output is correct
14 Correct 3 ms 18780 KB Output is correct
15 Correct 3 ms 18884 KB Output is correct
16 Correct 6 ms 18780 KB Output is correct
17 Correct 3 ms 18780 KB Output is correct
18 Correct 3 ms 18780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 18776 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 18952 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 3 ms 18780 KB Output is correct
10 Correct 2 ms 18780 KB Output is correct
11 Correct 3 ms 18780 KB Output is correct
12 Correct 2 ms 18912 KB Output is correct
13 Correct 2 ms 18780 KB Output is correct
14 Correct 3 ms 18780 KB Output is correct
15 Correct 3 ms 18884 KB Output is correct
16 Correct 6 ms 18780 KB Output is correct
17 Correct 3 ms 18780 KB Output is correct
18 Correct 3 ms 18780 KB Output is correct
19 Incorrect 3 ms 18780 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 18776 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 18952 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 3 ms 18780 KB Output is correct
10 Correct 2 ms 18780 KB Output is correct
11 Correct 3 ms 18780 KB Output is correct
12 Correct 2 ms 18912 KB Output is correct
13 Correct 2 ms 18780 KB Output is correct
14 Correct 3 ms 18780 KB Output is correct
15 Correct 3 ms 18884 KB Output is correct
16 Correct 6 ms 18780 KB Output is correct
17 Correct 3 ms 18780 KB Output is correct
18 Correct 3 ms 18780 KB Output is correct
19 Incorrect 221 ms 70052 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 18776 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 18952 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 3 ms 18780 KB Output is correct
10 Correct 2 ms 18780 KB Output is correct
11 Correct 3 ms 18780 KB Output is correct
12 Correct 2 ms 18912 KB Output is correct
13 Correct 2 ms 18780 KB Output is correct
14 Correct 3 ms 18780 KB Output is correct
15 Correct 3 ms 18884 KB Output is correct
16 Correct 6 ms 18780 KB Output is correct
17 Correct 3 ms 18780 KB Output is correct
18 Correct 3 ms 18780 KB Output is correct
19 Incorrect 3 ms 18780 KB Output isn't correct
20 Halted 0 ms 0 KB -