http://poj.org/problem?id=2599

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std; int n,k,pos;
vector<int> g[1005];
bool flag[1005]; int dfs(int k)
{
for(int i=0;i<g[k].size();i++)
{
int t=g[k][i];
if(!flag[t])
{
flag[t]=1;
if(!dfs(t))
{
pos=t;
return 1;//k状态为败,则i状态为胜
}
flag[t]=0;//初始化,进行下一次遍历
}
}
return 0;
} int main()
{
int n,k;
while(~scanf("%d%d",&n,&k))
{
for(int i=1;i<=n;i++)
g[i].clear();
for(int i=1;i<n;i++)
{
int u,v;
scanf("%d%d",&u,&v);
g[u].push_back(v);
g[v].push_back(u);
}
memset(flag,0,sizeof(flag));
flag[k]=1;
if(dfs(k)) printf("First player wins flying to airport %d\n",pos);
else printf("First player loses\n");
}
return 0;
}

POJ 2599 A funny game#树形SG(DFS实现)的更多相关文章

  1. poj 3140 Contestants Division(树形dp? dfs计数+枚举)

    本文出自   http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...

  2. POJ 2425 A Chess Game#树形SG

    http://poj.org/problem?id=2425 #include<iostream> #include<cstdio> #include<cstring&g ...

  3. poj 3710 Christmas Game【博弈论+SG】

    也就是转换到树形删边游戏,详见 https://wenku.baidu.com/view/25540742a8956bec0975e3a8.html #include<iostream> ...

  4. HDU 5293 Annoying problem 树形dp dfs序 树状数组 lca

    Annoying problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5293 Description Coco has a tree, w ...

  5. POJ 2023 Choose Your Own Adventure(树形,dfs,简单题)

    题意: 输入一个整数n,表示有n组测试数据, 每组第一行输入一个整数x表示该组测试一共有x页,接下来输入x行,每行表示一页, 每页或者以C开头(第一页都是以C开头),或者以E开头,中间用引号括起一段文 ...

  6. 【POJ 2486】 Apple Tree (树形DP)

    Apple Tree Description Wshxzt is a lovely girl. She likes apple very much. One day HX takes her to a ...

  7. POJ 3140.Contestants Division 基础树形dp

    Contestants Division Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10704   Accepted:  ...

  8. POJ 2425 A Chess Game 博弈论 sg函数

    http://poj.org/problem?id=2425 典型的sg函数,建图搜sg函数预处理之后直接求每次游戏的异或和.仍然是因为看不懂题目卡了好久. 这道题大概有两个坑, 1.是搜索的时候vi ...

  9. 树的直径的求法即相关证明【树形DP || DFS】

    学习大佬:树的直径求法及证明 树的直径 定义: 一棵树的直径就是这棵树上存在的最长路径. 给定一棵树,树中每条边都有一个权值,树中两点之间的距离定义为连接两点的路径边权之和.树中最远的两个节点之间的距 ...

随机推荐

  1. 【01背包】HDU 1171 Big Event in HDU

    Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. Bu ...

  2. Kali

    http://zydhacker.blog.163.com/blog/static/211795073201447337920/

  3. AxonVR:体验有触觉有温度的VR世界

    提到VR,通常指的是 Oculus Rift 及 HTC Vive的头盔:它们以视觉及听觉使你感到身处虚拟世界.头盔成功的在视觉及听觉感官上蒙骗了你,但我们体验现实的感官不仅于此.绝大多数的VR产品忽 ...

  4. ASP.NET Core: Getting Started with ASP.NET MVC Core

    1. ASP.NET Core the Unified Framework ASP.NET Core的统一框架 2. New Solution Project 新的解决方案项目 src folder: ...

  5. ios 状态码

    9001 无网络 9002 url错误 9003 链接超时 9005 json解析错误 9503 503 error

  6. edittext设置为密文显示

    et_msg.setInputType(InputType.TYPE_CLASS_TEXT |InputType.TYPE_TEXT_VARIATION_PASSWORD);

  7. Android开源库loopj的android-async-http的 JsonHttpResponseHandler 存在死循环GC_CONCURRENT

    我现在用的是 AndroidAsyncHttp 1.4.4 版本,之前遇到一个很奇怪的问题, 当使用 JsonHttpResponseHandler 解析请求的页面出现服务器错误或其他情况返回的内容不 ...

  8. 集成shareSDK的微信、QQ API导致cocoaPods找不到类symbol问题的解决方法

    因为shareSDK的微信和QQ API都只支持32位的,而cocoaPods默认要支持64位的,所以如果在工程中导入这两个API会出问题. 解决方法我就不转载啦,原文在这里: http://blog ...

  9. laravel创建定时任务

    官方文档给出的教程已经很详细了,这里给出一些补充帮助大家理解. 英文文档:https://laravel.com/docs/5.2/scheduling 中文文档:https://laravel-ch ...

  10. 生成元(Digit Generator,ACM/ICPC Seoul 2005,UVa 1583)

    #include<cstdio>#include<cstdlib>#include<cstring>using namespace std;int t, n, a, ...