Submission #103827

#TimeUsernameProblemLanguageResultExecution timeMemory
103827luciocfMousetrap (CEOI17_mousetrap)C++14
0 / 100
5 ms1408 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 11; typedef pair<int, int> pii; int n, t, m; int pai[maxn]; int dp[1<<maxn][maxn][2]; bool is[maxn]; vector<pii> grafo[maxn]; int dfs(int u, int p) { for (auto v: grafo[u]) { if (v.first == p) continue; pai[v.first] = u; dfs(v.first, u); if (is[v.first]) is[u] = 1; } if (u == t-1) is[u] = 1; } int solve(int mask, int u, bool q) { if (u == t-1) return 0; if (dp[mask][u][q] != -1) return dp[mask][u][q]; bool ok = 0; for (auto pp: grafo[u]) { if (pp.first == pai[u]) continue; int e = pp.second; if (!(mask&(1<<e))) ok = 1; } if (!ok) return 1; int ans = 0; if (q == 1) ans = solve(mask, u, 0); for (auto pp: grafo[u]) { if (pp.first == pai[u]) continue; int v = pp.first, e = pp.second; if (!(mask&(1<<e))) { if (q) ans = min(ans, 1+solve(mask|(1<<e), u, 0)); else { if (is[v]) ans = max(ans, solve(mask|(1<<e), v, 1)); else ans = max(ans, solve(mask|(1<<e), v, 1)+solve(mask|(1<<e), u, 1)); } } } return dp[mask][u][q] = ans; } int main(void) { scanf("%d %d %d", &n, &t, &m); for (int i = 0; i < n-1; i++) { int u, v; scanf("%d %d", &u, &v); u--, v--; grafo[u].push_back({v, i}); grafo[v].push_back({u, i}); } dfs(m-1, -1); memset(dp, -1, sizeof dp); printf("%d\n", solve(0, m-1, 1)); }

Compilation message (stderr)

mousetrap.cpp: In function 'int dfs(int, int)':
mousetrap.cpp:30:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
mousetrap.cpp: In function 'int main()':
mousetrap.cpp:72:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &t, &m);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mousetrap.cpp:77:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...