Wannafly挑战赛25 - D 玩游戏(DFS+博弈)

版权声明:是自己手打的没错 https://blog.csdn.net/Mr_Treeeee/article/details/82913277

https://www.nowcoder.com/acm/contest/197/D

POINT:

我觉得题解说的很棒了。

题解:

题目中对于图的限制可以看做 1 到 n 的所有简单路径互不相交。 在结束游戏前的最后一步一定是剩下一条 1 到 n 的路径,并且路径上的权值全都是一。如 果剩下的最后一条路径确定了,游戏的总步数也确定了,那么先后手的胜负也确定了。 那么双方的策略就使尽可能使最后留下的路径是使自己必胜的路径,即尽可能切断使对方 必胜的路径。【切断一条路径需要的步数是这条路径上的权值的最小值】。我们只需要比较双方切断对方必胜的路径所需要的步数即可。

然后根据总权值的奇偶来讨论一下就行了。

大家都是盯着那些【切断一条路径需要的步数是这条路径上的权值的最小值】切的。

所以切的地方都是各顾各的,只是看谁要切的比较多而已

#include <stdio.h>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
#define LL long long
const int N = 1e5+55;
const int inf = 0x3f3f3f3f;

vector<int>G[N],W[N];
LL num[2];
int n,m;

int main()
{
	scanf("%d%d",&n,&m);
	LL sum=0;
	for(int i=1;i<=m;i++){
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		G[u].push_back(v);G[v].push_back(u);
		W[u].push_back(w);W[v].push_back(w);
		sum+=w;
	}
	dfs(1,-1,0,inf);
	int flag=0;
	if(sum&1){
		if(num[0]>=num[1]) flag=1;
	}else{
		if(num[1]>=num[0]) flag=1;
	}
	if(flag) printf("Yes\n");
	else printf("No\n");
}

猜你喜欢

转载自blog.csdn.net/Mr_Treeeee/article/details/82913277