답안 #103827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
103827 2019-04-02T20:33:46 Z luciocf Mousetrap (CEOI17_mousetrap) C++14
0 / 100
5 ms 1408 KB
#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

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);
   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 -