#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];
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);
}
}
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 dp[mask][u][q] = 1;
int ans = 0;
if (q == 1) ans = solve(mask, u, !q);
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, 1));
else ans = max(ans, solve(mask, v, !q)+solve(mask|(1<<e), u, !q));
}
}
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
mousetrap.cpp: In function 'int dfs(int, int)':
mousetrap.cpp:24:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
mousetrap.cpp: In function 'int main()':
mousetrap.cpp:62: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:67:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &u, &v);
~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Incorrect |
2 ms |
512 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
1408 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Incorrect |
2 ms |
512 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Incorrect |
2 ms |
512 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |