【贪心/博弈】CF1363C Game On Leave

CF1363C Game On Leaves

思路:

先考虑先手必胜的最后局面:节点(x)本身就是叶子节点;或将节点(x)看作根节点时,只剩下(2)个节点。

对于后者的情况,考虑之前的(n-2)个节点。只要第(n-2)个节点由后手取走即可,也就是(n-2)为偶数。

void solve()
{
	int n, x;
	cin >> n >> x;
	int du = 0;
	for (int i = 1; i <= n - 1; i++) {
		int u, v;
		cin >> u >> v;
		if (u == x || v == x) du++;
	}
	if (du == 1 || n < 2) cout << "Ayush" << endl;
	else {
		if ((n - 2) % 2 == 0) cout << "Ayush" << endl;
		else cout << "Ashish" << endl;
	}
}
原文地址:https://www.cnblogs.com/streamazure/p/13040968.html