Submission #155716

#TimeUsernameProblemLanguageResultExecution timeMemory
155716FischerMuseum (CEOI17_museum)C++11
100 / 100
886 ms784396 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 2; int n, k, x; int sz[maxn]; int memo[maxn][maxn][2]; int nxt[maxn<<1], head[maxn]; int to[maxn<<1], value[maxn<<1]; void dfs(int x, int p) { sz[x] = 1; memo[x][1][0] = memo[x][1][1] = 0; for (int e = head[x]; ~e; e = nxt[e]) { int v = to[e], w = value[e]; if (v == p) continue; dfs(v, x); for (int i = min(sz[x] + sz[v], k); i >= 2; --i) { for (int j = min(sz[v], i-1); j >= max(1, i - sz[x]); --j) { memo[x][i][1] = min(memo[x][i][1], min( memo[x][i-j][1] + memo[v][j][0] + (w<<1), memo[x][i-j][0] + memo[v][j][1] + w )); memo[x][i][0] = min(memo[x][i][0], memo[x][i-j][0] + memo[v][j][0] + (w<<1)); } } sz[x] += sz[v]; } } int main() { scanf("%d %d %d", &n, &k, &x); memset(head, -1, sizeof head); for (int i = 1; i <= n-1; ++i) { int a, b, c; scanf("%d %d %d", &a, &b, &c); to[i<<1] = b; value[i<<1] = c; nxt[i<<1] = head[a]; head[a] = i<<1; to[i<<1|1] = a; value[i<<1|1] = c; nxt[i<<1|1] = head[b]; head[b] = i<<1|1; } memset(memo, 63, sizeof memo); dfs(x, 0); printf("%d\n", memo[x][k][1]); return 0; }

Compilation message (stderr)

museum.cpp: In function 'int main()':
museum.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &k, &x);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
museum.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &a, &b, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...