Submission #1112851

# Submission time Handle Problem Language Result Execution time Memory
1112851 2024-11-15T03:03:14 Z kiethm07 Race (IOI11_race) C++11
21 / 100
139 ms 42420 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 = 1e5 + 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){
    ///a.size() >= b.size()
    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]);
//        cout << p.fi << " " << p.se << " " << tmp->fi << " " << tmp->se << " " << h[u] << "\n";
    }
    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]));
    }
//    cout << u << " " << res << "\n";
    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:50: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]
   50 |     for (int i = 0; i < a[u].size(); i++){
      |                     ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7504 KB Output is correct
2 Correct 5 ms 7504 KB Output is correct
3 Correct 6 ms 7504 KB Output is correct
4 Correct 5 ms 7504 KB Output is correct
5 Correct 8 ms 7504 KB Output is correct
6 Correct 6 ms 7504 KB Output is correct
7 Correct 6 ms 7504 KB Output is correct
8 Correct 6 ms 7504 KB Output is correct
9 Correct 5 ms 7504 KB Output is correct
10 Correct 5 ms 7504 KB Output is correct
11 Correct 5 ms 7452 KB Output is correct
12 Correct 6 ms 7504 KB Output is correct
13 Correct 5 ms 7504 KB Output is correct
14 Correct 6 ms 7504 KB Output is correct
15 Correct 5 ms 7504 KB Output is correct
16 Correct 5 ms 7504 KB Output is correct
17 Correct 5 ms 7504 KB Output is correct
18 Correct 5 ms 7504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7504 KB Output is correct
2 Correct 5 ms 7504 KB Output is correct
3 Correct 6 ms 7504 KB Output is correct
4 Correct 5 ms 7504 KB Output is correct
5 Correct 8 ms 7504 KB Output is correct
6 Correct 6 ms 7504 KB Output is correct
7 Correct 6 ms 7504 KB Output is correct
8 Correct 6 ms 7504 KB Output is correct
9 Correct 5 ms 7504 KB Output is correct
10 Correct 5 ms 7504 KB Output is correct
11 Correct 5 ms 7452 KB Output is correct
12 Correct 6 ms 7504 KB Output is correct
13 Correct 5 ms 7504 KB Output is correct
14 Correct 6 ms 7504 KB Output is correct
15 Correct 5 ms 7504 KB Output is correct
16 Correct 5 ms 7504 KB Output is correct
17 Correct 5 ms 7504 KB Output is correct
18 Correct 5 ms 7504 KB Output is correct
19 Correct 7 ms 7504 KB Output is correct
20 Correct 5 ms 7504 KB Output is correct
21 Correct 6 ms 7760 KB Output is correct
22 Correct 7 ms 7760 KB Output is correct
23 Correct 6 ms 7760 KB Output is correct
24 Correct 6 ms 7816 KB Output is correct
25 Correct 7 ms 7760 KB Output is correct
26 Correct 6 ms 7760 KB Output is correct
27 Correct 7 ms 7504 KB Output is correct
28 Correct 7 ms 7760 KB Output is correct
29 Correct 7 ms 7760 KB Output is correct
30 Correct 7 ms 7760 KB Output is correct
31 Correct 6 ms 8012 KB Output is correct
32 Correct 6 ms 7760 KB Output is correct
33 Correct 6 ms 7752 KB Output is correct
34 Correct 6 ms 7760 KB Output is correct
35 Correct 8 ms 7760 KB Output is correct
36 Correct 7 ms 7504 KB Output is correct
37 Correct 7 ms 7504 KB Output is correct
38 Correct 7 ms 7760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7504 KB Output is correct
2 Correct 5 ms 7504 KB Output is correct
3 Correct 6 ms 7504 KB Output is correct
4 Correct 5 ms 7504 KB Output is correct
5 Correct 8 ms 7504 KB Output is correct
6 Correct 6 ms 7504 KB Output is correct
7 Correct 6 ms 7504 KB Output is correct
8 Correct 6 ms 7504 KB Output is correct
9 Correct 5 ms 7504 KB Output is correct
10 Correct 5 ms 7504 KB Output is correct
11 Correct 5 ms 7452 KB Output is correct
12 Correct 6 ms 7504 KB Output is correct
13 Correct 5 ms 7504 KB Output is correct
14 Correct 6 ms 7504 KB Output is correct
15 Correct 5 ms 7504 KB Output is correct
16 Correct 5 ms 7504 KB Output is correct
17 Correct 5 ms 7504 KB Output is correct
18 Correct 5 ms 7504 KB Output is correct
19 Correct 102 ms 30300 KB Output is correct
20 Correct 108 ms 29000 KB Output is correct
21 Correct 100 ms 29996 KB Output is correct
22 Correct 92 ms 29736 KB Output is correct
23 Correct 139 ms 42420 KB Output is correct
24 Correct 113 ms 33080 KB Output is correct
25 Correct 84 ms 28488 KB Output is correct
26 Correct 55 ms 34632 KB Output is correct
27 Runtime error 55 ms 22424 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7504 KB Output is correct
2 Correct 5 ms 7504 KB Output is correct
3 Correct 6 ms 7504 KB Output is correct
4 Correct 5 ms 7504 KB Output is correct
5 Correct 8 ms 7504 KB Output is correct
6 Correct 6 ms 7504 KB Output is correct
7 Correct 6 ms 7504 KB Output is correct
8 Correct 6 ms 7504 KB Output is correct
9 Correct 5 ms 7504 KB Output is correct
10 Correct 5 ms 7504 KB Output is correct
11 Correct 5 ms 7452 KB Output is correct
12 Correct 6 ms 7504 KB Output is correct
13 Correct 5 ms 7504 KB Output is correct
14 Correct 6 ms 7504 KB Output is correct
15 Correct 5 ms 7504 KB Output is correct
16 Correct 5 ms 7504 KB Output is correct
17 Correct 5 ms 7504 KB Output is correct
18 Correct 5 ms 7504 KB Output is correct
19 Correct 7 ms 7504 KB Output is correct
20 Correct 5 ms 7504 KB Output is correct
21 Correct 6 ms 7760 KB Output is correct
22 Correct 7 ms 7760 KB Output is correct
23 Correct 6 ms 7760 KB Output is correct
24 Correct 6 ms 7816 KB Output is correct
25 Correct 7 ms 7760 KB Output is correct
26 Correct 6 ms 7760 KB Output is correct
27 Correct 7 ms 7504 KB Output is correct
28 Correct 7 ms 7760 KB Output is correct
29 Correct 7 ms 7760 KB Output is correct
30 Correct 7 ms 7760 KB Output is correct
31 Correct 6 ms 8012 KB Output is correct
32 Correct 6 ms 7760 KB Output is correct
33 Correct 6 ms 7752 KB Output is correct
34 Correct 6 ms 7760 KB Output is correct
35 Correct 8 ms 7760 KB Output is correct
36 Correct 7 ms 7504 KB Output is correct
37 Correct 7 ms 7504 KB Output is correct
38 Correct 7 ms 7760 KB Output is correct
39 Correct 102 ms 30300 KB Output is correct
40 Correct 108 ms 29000 KB Output is correct
41 Correct 100 ms 29996 KB Output is correct
42 Correct 92 ms 29736 KB Output is correct
43 Correct 139 ms 42420 KB Output is correct
44 Correct 113 ms 33080 KB Output is correct
45 Correct 84 ms 28488 KB Output is correct
46 Correct 55 ms 34632 KB Output is correct
47 Runtime error 55 ms 22424 KB Execution killed with signal 11
48 Halted 0 ms 0 KB -