Submission #952140

# Submission time Handle Problem Language Result Execution time Memory
952140 2024-03-23T06:37:42 Z vjudge1 Museum (CEOI17_museum) C++17
80 / 100
3000 ms 784816 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 5;
const int maxv = 1e4 + 5;
using ll = long long;
int dp[maxn][maxv][2];
int n, k;
vector<pair<int, int>> G[maxn];
int st;
int siz[maxn];
void dfs(int x, int fa)
{
	siz[x] = 1;
    for (auto p : G[x])
    {
        int y = p.first;
        int w = p.second;
        if (y == fa)
            continue;
        dfs(y, x);
        siz[x] += siz[y]; 
        for (int i = min(k, siz[x]); i >= 0; i--)
        {
            for (int j = 0; j <= min(k - i, siz[y]); j++)
            {
                dp[x][i + j][0] = min(dp[x][i + j][0], dp[x][i][0] + dp[y][j][0] + w * 2);
                dp[x][i + j][1] = min(dp[x][i + j][1], dp[x][i][1] + dp[y][j][0] + w * 2);
                dp[x][i + j][1] = min(dp[x][i + j][1], dp[x][i][0] + dp[y][j][1] + w);
            }
        }
    }
}
int main()
{
//    freopen("museum.in", "r", stdin);
//    freopen("museum.out", "w", stdout);
    scanf("%d%d%d", &n, &k, &st);
    for (int i = 1; i <= n - 1; i++)
    {
        int u, v;
        int x;
        scanf("%d%d%d", &u, &v, &x);
        G[u].push_back(make_pair(v, x));
        G[v].push_back(make_pair(u, x));
    }
    if(k == 1){
    	printf("0\n");
    	return 0;
	}
    memset(dp, 0x3f, sizeof dp);
    for (int i = 1; i <= n; i++)
    {
        dp[i][1][0] = dp[i][1][1] = 0;
    }
    dfs(st, 0);
    printf("%d\n", min(dp[st][k][1], dp[st][k][0]));
    return 0;
}

Compilation message

museum.cpp: In function 'int main()':
museum.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     scanf("%d%d%d", &n, &k, &st);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
museum.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf("%d%d%d", &u, &v, &x);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 374 ms 784208 KB Output is correct
2 Correct 219 ms 784208 KB Output is correct
3 Correct 214 ms 784028 KB Output is correct
4 Correct 220 ms 784208 KB Output is correct
5 Correct 222 ms 784212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 230 ms 784440 KB Output is correct
2 Correct 228 ms 784492 KB Output is correct
3 Correct 267 ms 784764 KB Output is correct
4 Correct 248 ms 784508 KB Output is correct
5 Correct 251 ms 784464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 230 ms 784440 KB Output is correct
2 Correct 228 ms 784492 KB Output is correct
3 Correct 267 ms 784764 KB Output is correct
4 Correct 248 ms 784508 KB Output is correct
5 Correct 251 ms 784464 KB Output is correct
6 Correct 230 ms 784540 KB Output is correct
7 Correct 276 ms 784812 KB Output is correct
8 Correct 280 ms 784816 KB Output is correct
9 Correct 236 ms 784512 KB Output is correct
10 Correct 235 ms 784660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 374 ms 784208 KB Output is correct
2 Correct 219 ms 784208 KB Output is correct
3 Correct 214 ms 784028 KB Output is correct
4 Correct 220 ms 784208 KB Output is correct
5 Correct 222 ms 784212 KB Output is correct
6 Correct 230 ms 784440 KB Output is correct
7 Correct 228 ms 784492 KB Output is correct
8 Correct 267 ms 784764 KB Output is correct
9 Correct 248 ms 784508 KB Output is correct
10 Correct 251 ms 784464 KB Output is correct
11 Correct 230 ms 784540 KB Output is correct
12 Correct 276 ms 784812 KB Output is correct
13 Correct 280 ms 784816 KB Output is correct
14 Correct 236 ms 784512 KB Output is correct
15 Correct 235 ms 784660 KB Output is correct
16 Correct 298 ms 784468 KB Output is correct
17 Correct 843 ms 784648 KB Output is correct
18 Correct 2028 ms 784772 KB Output is correct
19 Correct 296 ms 784708 KB Output is correct
20 Correct 265 ms 784448 KB Output is correct
21 Execution timed out 3075 ms 784724 KB Time limit exceeded
22 Halted 0 ms 0 KB -