Submission #1068232

# Submission time Handle Problem Language Result Execution time Memory
1068232 2024-08-21T08:46:25 Z Kipras Race (IOI11_race) C++17
21 / 100
3000 ms 27988 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

constexpr ll maxN = 2e5+10;
constexpr ll inf = 1e15;

vector<pair<ll, ll>> adj[maxN];
ll res = inf, k;

map<ll, ll> dfs(ll v, ll p, ll konst, ll dep) {

    map<ll, ll> mp;

    mp[konst]=dep;

    for(auto i : adj[v]) {
        if(i.first==p)continue;
        map<ll, ll> tmp = dfs(i.first, v, i.second+konst, dep+1);
        if(tmp.size()<mp.size())swap(mp, tmp);
        for(auto x : tmp) {
            ll val = x.first;
            ll dep1 = x.second;
            ll needed = k+2*konst-val;
            if(mp.count(needed)) {
                ll dep2 = mp[needed];
                res=min(res, dep1+dep2-2*dep);
            }
        }
        for(auto x : tmp) {
            if(!mp.count(x.first))mp[x.first]=x.second;
            else mp[x.first]=min(x.second, mp[x.first]);
        }
    }

    return mp;

}

int best_path(int N, int K, int H[][2], int L[])
{
    k=K;
    for(int i = 0; i < N-1; i++) {
        ll aa = H[i][0], bb = H[i][1];

        adj[aa].push_back({bb, L[i]});
        adj[bb].push_back({aa, L[i]});
    }

    dfs(0, -1, 0, 0);

    if(res==inf) {
        return -1;
    }

    return res;
}

/*int nn, kk;
int H[maxN][2];
int L[maxN];
int solution;

int main()
{
    cin>>nn>>kk;
    for(int i = 0; i < nn-1; i++) {
        cin>>H[i][0]>>H[i][1];
    }
    for(int i = 0; i < nn-1; i++) {
        cin>>L[i];
    }
    cout<<best_path(nn,kk,H,L);

    return 0;
}
*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 3 ms 5144 KB Output is correct
11 Correct 3 ms 4952 KB Output is correct
12 Correct 3 ms 6744 KB Output is correct
13 Correct 3 ms 5020 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 3 ms 5144 KB Output is correct
11 Correct 3 ms 4952 KB Output is correct
12 Correct 3 ms 6744 KB Output is correct
13 Correct 3 ms 5020 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 4 ms 5212 KB Output is correct
22 Correct 4 ms 5212 KB Output is correct
23 Correct 6 ms 5224 KB Output is correct
24 Correct 7 ms 5208 KB Output is correct
25 Correct 6 ms 5212 KB Output is correct
26 Correct 5 ms 5212 KB Output is correct
27 Correct 3 ms 6748 KB Output is correct
28 Correct 6 ms 5300 KB Output is correct
29 Correct 6 ms 5212 KB Output is correct
30 Correct 5 ms 5152 KB Output is correct
31 Correct 5 ms 5212 KB Output is correct
32 Correct 5 ms 6744 KB Output is correct
33 Correct 5 ms 6748 KB Output is correct
34 Correct 10 ms 5212 KB Output is correct
35 Correct 14 ms 5152 KB Output is correct
36 Correct 13 ms 5212 KB Output is correct
37 Correct 7 ms 5212 KB Output is correct
38 Correct 6 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 3 ms 5144 KB Output is correct
11 Correct 3 ms 4952 KB Output is correct
12 Correct 3 ms 6744 KB Output is correct
13 Correct 3 ms 5020 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 105 ms 14404 KB Output is correct
20 Correct 103 ms 14420 KB Output is correct
21 Correct 92 ms 14424 KB Output is correct
22 Correct 112 ms 14456 KB Output is correct
23 Correct 112 ms 14844 KB Output is correct
24 Correct 106 ms 14116 KB Output is correct
25 Execution timed out 3083 ms 27988 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 3 ms 5144 KB Output is correct
11 Correct 3 ms 4952 KB Output is correct
12 Correct 3 ms 6744 KB Output is correct
13 Correct 3 ms 5020 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 4 ms 5212 KB Output is correct
22 Correct 4 ms 5212 KB Output is correct
23 Correct 6 ms 5224 KB Output is correct
24 Correct 7 ms 5208 KB Output is correct
25 Correct 6 ms 5212 KB Output is correct
26 Correct 5 ms 5212 KB Output is correct
27 Correct 3 ms 6748 KB Output is correct
28 Correct 6 ms 5300 KB Output is correct
29 Correct 6 ms 5212 KB Output is correct
30 Correct 5 ms 5152 KB Output is correct
31 Correct 5 ms 5212 KB Output is correct
32 Correct 5 ms 6744 KB Output is correct
33 Correct 5 ms 6748 KB Output is correct
34 Correct 10 ms 5212 KB Output is correct
35 Correct 14 ms 5152 KB Output is correct
36 Correct 13 ms 5212 KB Output is correct
37 Correct 7 ms 5212 KB Output is correct
38 Correct 6 ms 5212 KB Output is correct
39 Correct 105 ms 14404 KB Output is correct
40 Correct 103 ms 14420 KB Output is correct
41 Correct 92 ms 14424 KB Output is correct
42 Correct 112 ms 14456 KB Output is correct
43 Correct 112 ms 14844 KB Output is correct
44 Correct 106 ms 14116 KB Output is correct
45 Execution timed out 3083 ms 27988 KB Time limit exceeded
46 Halted 0 ms 0 KB -