Submission #156490

# Submission time Handle Problem Language Result Execution time Memory
156490 2019-10-06T07:50:11 Z lyc Museum (CEOI17_museum) C++14
100 / 100
942 ms 785164 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MX_N = 10005;
int N, K, X, A, B, C;
vector<ii> al[MX_N];
int f[MX_N][MX_N][2], g[MX_N];

void dfs(int u, int p) {
    g[u] = 1;
    f[u][1][0] = f[u][1][1] = 0;
    for (auto v : al[u]) if (v.fi != p) {
        dfs(v.fi,u);
        RFOR(j,g[u],1) FOR(k,1,g[v.fi]){
            f[u][j+k][0] = min(f[u][j+k][0], f[u][j][0] + f[v.fi][k][0] + 2*v.sc);
            f[u][j+k][1] = min(f[u][j+k][1], f[u][j][0] + f[v.fi][k][1] + v.sc);
            f[u][j+k][1] = min(f[u][j+k][1], f[u][j][1] + f[v.fi][k][0] + 2*v.sc);
        }
        g[u] += g[v.fi];
    }
    //printf("%d (%d):\n", u, g[u]);
    //FOR(j,0,g[u]) printf("%d ", f[u][j][0]);
    //printf("\n");
    //FOR(j,0,g[u]) printf("%d ", f[u][j][1]);
    //printf("\n");
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> K >> X;
    memset(f,63,sizeof f);
    FOR(i,1,N-1){ cin >> A >> B >> C; al[A].emplace_back(B,C); al[B].emplace_back(A,C); }
    dfs(X,0);
    cout << f[X][K][1] << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 792 ms 784200 KB Output is correct
2 Correct 651 ms 784256 KB Output is correct
3 Correct 653 ms 784200 KB Output is correct
4 Correct 654 ms 784156 KB Output is correct
5 Correct 668 ms 784248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 849 ms 784820 KB Output is correct
2 Correct 863 ms 784832 KB Output is correct
3 Correct 825 ms 785144 KB Output is correct
4 Correct 858 ms 784968 KB Output is correct
5 Correct 814 ms 784776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 849 ms 784820 KB Output is correct
2 Correct 863 ms 784832 KB Output is correct
3 Correct 825 ms 785144 KB Output is correct
4 Correct 858 ms 784968 KB Output is correct
5 Correct 814 ms 784776 KB Output is correct
6 Correct 833 ms 784924 KB Output is correct
7 Correct 849 ms 785124 KB Output is correct
8 Correct 862 ms 784964 KB Output is correct
9 Correct 845 ms 784952 KB Output is correct
10 Correct 813 ms 784708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 792 ms 784200 KB Output is correct
2 Correct 651 ms 784256 KB Output is correct
3 Correct 653 ms 784200 KB Output is correct
4 Correct 654 ms 784156 KB Output is correct
5 Correct 668 ms 784248 KB Output is correct
6 Correct 849 ms 784820 KB Output is correct
7 Correct 863 ms 784832 KB Output is correct
8 Correct 825 ms 785144 KB Output is correct
9 Correct 858 ms 784968 KB Output is correct
10 Correct 814 ms 784776 KB Output is correct
11 Correct 833 ms 784924 KB Output is correct
12 Correct 849 ms 785124 KB Output is correct
13 Correct 862 ms 784964 KB Output is correct
14 Correct 845 ms 784952 KB Output is correct
15 Correct 813 ms 784708 KB Output is correct
16 Correct 837 ms 784812 KB Output is correct
17 Correct 897 ms 784868 KB Output is correct
18 Correct 942 ms 785048 KB Output is correct
19 Correct 851 ms 784760 KB Output is correct
20 Correct 813 ms 784784 KB Output is correct
21 Correct 823 ms 785040 KB Output is correct
22 Correct 814 ms 784828 KB Output is correct
23 Correct 852 ms 784708 KB Output is correct
24 Correct 815 ms 784848 KB Output is correct
25 Correct 838 ms 785164 KB Output is correct