Submission #1112852

# Submission time Handle Problem Language Result Execution time Memory
1112852 2024-11-15T03:04:00 Z kiethm07 Race (IOI11_race) C++11
100 / 100
410 ms 104008 KB
#include <bits/stdc++.h>
#include <race.h>

#define pii pair<int,int>
#define iii pair<int,pii>
#define fi first
#define se second

#define vi vector<int>
#define all(x) x.begin(),x.end()

#define TEXT "a"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int inf = 1e9 + 7;
const ld eps = 1e-8;
const double pi = acos(-1);
const int N = 2e5 + 5;

vector<pii> a[N];
int n;
ll k;
map<ll,int> mp[N];
int h[N], sz[N];
ll f[N];

int combine(int u,map<ll,int>& a, map<ll,int>& b){
    int res = inf;
    for (pii p : b){
        auto tmp = a.find(k - p.fi + 2 * f[u]);
        if (tmp == a.end()) continue;
        res = min(res, p.second + tmp->second - 2 * h[u]);
    }
    for (pii p : b){
        if (a.find(p.fi) != a.end()) a[p.fi] = min(a[p.fi], p.se);
        else a[p.fi] = p.se;
    }
    return res;
}

int dfs(int u,int p = -1){
    int res = inf;
    for (int i = 0; i < a[u].size(); i++){
        int v = a[u][i].fi;
        int w = a[u][i].se;
        if (v == p) continue;
        h[v] = h[u] + 1;
        f[v] = f[u] + w;
        mp[v][f[v]] = h[v];
        int tmp = dfs(v,u);
        res = min(res, tmp);
        if (mp[u].size() < mp[v].size()) swap(mp[u], mp[v]);
        res = min(res, combine(u,mp[u],mp[v]));
    }
    return res;
}

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 u = H[i][0] + 1;
        int v = H[i][1] + 1;
        int w = L[i];
        a[u].push_back(pii(v,w));
        a[v].push_back(pii(u,w));
    }
    int res = dfs(1,-1);
    if (res == inf) res = -1;
    return res;
}

Compilation message

race.cpp: In function 'int dfs(int, int)':
race.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int i = 0; i < a[u].size(); i++){
      |                     ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14416 KB Output is correct
2 Correct 9 ms 14528 KB Output is correct
3 Correct 9 ms 14416 KB Output is correct
4 Correct 10 ms 14416 KB Output is correct
5 Correct 10 ms 14428 KB Output is correct
6 Correct 10 ms 14416 KB Output is correct
7 Correct 10 ms 14416 KB Output is correct
8 Correct 9 ms 14416 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 10 ms 14592 KB Output is correct
11 Correct 9 ms 14448 KB Output is correct
12 Correct 9 ms 14428 KB Output is correct
13 Correct 9 ms 14416 KB Output is correct
14 Correct 9 ms 14376 KB Output is correct
15 Correct 9 ms 14416 KB Output is correct
16 Correct 10 ms 14416 KB Output is correct
17 Correct 9 ms 14368 KB Output is correct
18 Correct 10 ms 14416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14416 KB Output is correct
2 Correct 9 ms 14528 KB Output is correct
3 Correct 9 ms 14416 KB Output is correct
4 Correct 10 ms 14416 KB Output is correct
5 Correct 10 ms 14428 KB Output is correct
6 Correct 10 ms 14416 KB Output is correct
7 Correct 10 ms 14416 KB Output is correct
8 Correct 9 ms 14416 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 10 ms 14592 KB Output is correct
11 Correct 9 ms 14448 KB Output is correct
12 Correct 9 ms 14428 KB Output is correct
13 Correct 9 ms 14416 KB Output is correct
14 Correct 9 ms 14376 KB Output is correct
15 Correct 9 ms 14416 KB Output is correct
16 Correct 10 ms 14416 KB Output is correct
17 Correct 9 ms 14368 KB Output is correct
18 Correct 10 ms 14416 KB Output is correct
19 Correct 10 ms 14416 KB Output is correct
20 Correct 9 ms 14508 KB Output is correct
21 Correct 10 ms 14672 KB Output is correct
22 Correct 10 ms 14672 KB Output is correct
23 Correct 10 ms 14672 KB Output is correct
24 Correct 11 ms 14672 KB Output is correct
25 Correct 12 ms 14672 KB Output is correct
26 Correct 10 ms 14744 KB Output is correct
27 Correct 10 ms 14672 KB Output is correct
28 Correct 10 ms 14672 KB Output is correct
29 Correct 10 ms 14672 KB Output is correct
30 Correct 11 ms 14672 KB Output is correct
31 Correct 12 ms 14732 KB Output is correct
32 Correct 11 ms 14688 KB Output is correct
33 Correct 11 ms 14844 KB Output is correct
34 Correct 11 ms 14672 KB Output is correct
35 Correct 12 ms 14672 KB Output is correct
36 Correct 10 ms 14672 KB Output is correct
37 Correct 12 ms 14672 KB Output is correct
38 Correct 10 ms 14672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14416 KB Output is correct
2 Correct 9 ms 14528 KB Output is correct
3 Correct 9 ms 14416 KB Output is correct
4 Correct 10 ms 14416 KB Output is correct
5 Correct 10 ms 14428 KB Output is correct
6 Correct 10 ms 14416 KB Output is correct
7 Correct 10 ms 14416 KB Output is correct
8 Correct 9 ms 14416 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 10 ms 14592 KB Output is correct
11 Correct 9 ms 14448 KB Output is correct
12 Correct 9 ms 14428 KB Output is correct
13 Correct 9 ms 14416 KB Output is correct
14 Correct 9 ms 14376 KB Output is correct
15 Correct 9 ms 14416 KB Output is correct
16 Correct 10 ms 14416 KB Output is correct
17 Correct 9 ms 14368 KB Output is correct
18 Correct 10 ms 14416 KB Output is correct
19 Correct 122 ms 36168 KB Output is correct
20 Correct 121 ms 36176 KB Output is correct
21 Correct 116 ms 35656 KB Output is correct
22 Correct 112 ms 35336 KB Output is correct
23 Correct 160 ms 47944 KB Output is correct
24 Correct 122 ms 38728 KB Output is correct
25 Correct 92 ms 34184 KB Output is correct
26 Correct 60 ms 40264 KB Output is correct
27 Correct 173 ms 45716 KB Output is correct
28 Correct 241 ms 81480 KB Output is correct
29 Correct 260 ms 80208 KB Output is correct
30 Correct 179 ms 48712 KB Output is correct
31 Correct 165 ms 48200 KB Output is correct
32 Correct 222 ms 48456 KB Output is correct
33 Correct 187 ms 53208 KB Output is correct
34 Correct 292 ms 86344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14416 KB Output is correct
2 Correct 9 ms 14528 KB Output is correct
3 Correct 9 ms 14416 KB Output is correct
4 Correct 10 ms 14416 KB Output is correct
5 Correct 10 ms 14428 KB Output is correct
6 Correct 10 ms 14416 KB Output is correct
7 Correct 10 ms 14416 KB Output is correct
8 Correct 9 ms 14416 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 10 ms 14592 KB Output is correct
11 Correct 9 ms 14448 KB Output is correct
12 Correct 9 ms 14428 KB Output is correct
13 Correct 9 ms 14416 KB Output is correct
14 Correct 9 ms 14376 KB Output is correct
15 Correct 9 ms 14416 KB Output is correct
16 Correct 10 ms 14416 KB Output is correct
17 Correct 9 ms 14368 KB Output is correct
18 Correct 10 ms 14416 KB Output is correct
19 Correct 10 ms 14416 KB Output is correct
20 Correct 9 ms 14508 KB Output is correct
21 Correct 10 ms 14672 KB Output is correct
22 Correct 10 ms 14672 KB Output is correct
23 Correct 10 ms 14672 KB Output is correct
24 Correct 11 ms 14672 KB Output is correct
25 Correct 12 ms 14672 KB Output is correct
26 Correct 10 ms 14744 KB Output is correct
27 Correct 10 ms 14672 KB Output is correct
28 Correct 10 ms 14672 KB Output is correct
29 Correct 10 ms 14672 KB Output is correct
30 Correct 11 ms 14672 KB Output is correct
31 Correct 12 ms 14732 KB Output is correct
32 Correct 11 ms 14688 KB Output is correct
33 Correct 11 ms 14844 KB Output is correct
34 Correct 11 ms 14672 KB Output is correct
35 Correct 12 ms 14672 KB Output is correct
36 Correct 10 ms 14672 KB Output is correct
37 Correct 12 ms 14672 KB Output is correct
38 Correct 10 ms 14672 KB Output is correct
39 Correct 122 ms 36168 KB Output is correct
40 Correct 121 ms 36176 KB Output is correct
41 Correct 116 ms 35656 KB Output is correct
42 Correct 112 ms 35336 KB Output is correct
43 Correct 160 ms 47944 KB Output is correct
44 Correct 122 ms 38728 KB Output is correct
45 Correct 92 ms 34184 KB Output is correct
46 Correct 60 ms 40264 KB Output is correct
47 Correct 173 ms 45716 KB Output is correct
48 Correct 241 ms 81480 KB Output is correct
49 Correct 260 ms 80208 KB Output is correct
50 Correct 179 ms 48712 KB Output is correct
51 Correct 165 ms 48200 KB Output is correct
52 Correct 222 ms 48456 KB Output is correct
53 Correct 187 ms 53208 KB Output is correct
54 Correct 292 ms 86344 KB Output is correct
55 Correct 24 ms 17756 KB Output is correct
56 Correct 16 ms 16464 KB Output is correct
57 Correct 72 ms 34632 KB Output is correct
58 Correct 46 ms 27968 KB Output is correct
59 Correct 82 ms 47944 KB Output is correct
60 Correct 268 ms 80636 KB Output is correct
61 Correct 182 ms 52296 KB Output is correct
62 Correct 166 ms 49044 KB Output is correct
63 Correct 227 ms 47688 KB Output is correct
64 Correct 410 ms 104008 KB Output is correct
65 Correct 387 ms 101960 KB Output is correct
66 Correct 284 ms 77640 KB Output is correct
67 Correct 138 ms 43192 KB Output is correct
68 Correct 336 ms 65756 KB Output is correct
69 Correct 334 ms 70732 KB Output is correct
70 Correct 315 ms 63560 KB Output is correct