title: NEERC 2016-2017 Probelm G. Game on Graph
data: 2018-3-3 22:25:40
tags:

  • 博弈论
  • with draw
  • 拓扑排序
    categories:
  • 信息学竞赛
  • 题目
    description: 有一个有向图, 两人依次移动一个棋子, 谁不能移动谁输, 对于玩家二它如果不能赢宁愿选择输, 问先手为玩家一或二棋子初始在任意位置时先手输或赢或者是平局?
    ---
    NEERC 2016-2017 Probelm G. Game on Graph

    Description

      Gennady and Georgiy are playing interesting game on a directed graph. The graph has n vertices and m arcs, loops are allowed. Gennady and Georgiy have a token placed in one of the graph vertices. Players take turns moving the token along one of the arcs that starts in the vertex the token is currently in. When there is no such arc, then this player loses the game.

  For each initial position of the token and the player who is moving first, your task is to determine what kind of result the game is going to have. Does it seem to be easy? Not so much.

  On one side, Gennady is having a lot of fun playing this game, so he wants to play as long as possible. He even prefers a strategy that leads to infinite game to a strategy that makes him a winner. But if he cannot make the game infinite, then he obviously prefers winning to losing.

  On the other side, Georgiy has a lot of other work, so he does not want to play the game infinitely.
Georgiy wants to win the game, but if he cannot win, then he prefers losing game to making it infinite.
Both players are playing optimally. Both players know preferences of the other player.

Input

  In the first line there are two integers — the number of vertices n (1 ≤ n ≤ 100 000) and the number of arcs m (1 ≤ m ≤ 200 000). In the next m lines there are two integers a and b on each line, denoting an arc from vertex a to vertex b. Vertices are numbered from 1 to n. Each (a, b) tuple appears at most once.

Output

  In the first line print n characters — i-th character should denote the result of the game if Gennady starts in vertex i. In the second line print n characters — i-th character should denote the result of the game if Georgiy starts in vertex i. The result of the game is denoted by “W” if the starting player wins the game, “L” if the starting player loses the game, and “D” (draw) if the game runs infinitely.

Example

6 7
1 2
2 1
2 3
1 4
4 1
4 5
5 6
WDLDWL
DWLLWL

Note

  In vertices 3 and 6 the game is already lost. In vertex 5, the only move is to vertex 6, and the player wins. If Georgiy starts in vertex 1, or Gennady in vertices 2 or 4, Gennady can always go to vertex 1, and make the game infinite. If Georgiy starts in vertex 4, he can either go to vertex 1 (which leads to a draw) or to vertex 5, which leads to losing. Georgiy prefers the latter. Similarly, from vertex 2, he prefers to go to 3 and win. From vertex 1, Gennady can go to vertex 2 and lose, or go to vertex 4 and win. He prefers the latter.

做法:

  首先这道题特殊的地方在于玩家二的特殊要求, 对它来说输比平局要好.所以我们在利用后继状态确立胜负的时候, 就要做出一些改变.

  • 对于玩家二为先手来说, 如果一个状态的后继状态有一个不为平局, 那么一定不为平局.
  • 对于玩家一为先手来说, 如果一个状态的后继状态都不为平局, 其一定不为平局.
      先利用拓扑排序确立出平局状态, 平局状态一定不会出现在拓扑序中.接着标记出所有的胜负状态, 剩下那些没有被标记的就是可能为平局状态, 但是因为玩家二的特殊, 所以这些状态一定是玩家一胜利.

NEERC 2016-2017 Probelm G. Game on Graph的更多相关文章

  1. 【转】2016/2017 Web 开发者路线图

    链接:知乎 [点击查看大图] 原图来自LearnCodeAcademy最火的视频,learncode是YouTube上最火的Web开发教学频道,介绍包括HTML/CSS/JavaScript/Subl ...

  2. Codeforces 1082 G - Petya and Graph

    G - Petya and Graph 思路: 最大权闭合子图 对于每条边,如果它选了,那么它连的的两个点也要选 边权为正,点权为负,那么就是求最大权闭合子图 代码: #pragma GCC opti ...

  3. 2016湖南省赛----G - Parenthesis (括号匹配)

    2016湖南省赛----G - Parenthesis (括号匹配)   Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of lengt ...

  4. Codeforces Gym 101190 NEERC 16 G. Game on Graph(博弈+拓扑)

    Gennady and Georgiy are playing interesting game on a directed graph. The graph has n vertices and m ...

  5. ACM ICPC 2016–2017, NEERC, Northern Subregional Contest Problem J. Java2016

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510 时间限制:2s 空间限制:256MB 题目大意: 给定一个数字c 用 " ...

  6. 2016 NEERC, Northern Subregional Contest G.Gangsters in Central City(LCA)

    G.Gangsters in Central City 题意:一棵树,节点1为根,是水源.水顺着边流至叶子.该树的每个叶子上有房子.有q个询问,一种为房子u被强盗入侵,另一种为强盗撤离房子u.对于每个 ...

  7. [SinGuLaRiTy] COCI 2016~2017 #5

    [SinGuLaRiTy-1012] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 最近神犇喜欢考COCI...... 测试题目 对于所有的 ...

  8. 关于ECMAScript 2016, 2017, 和2018中新增功能(摘抄)

    ECMAScript 2016 1. Array.prototype.includes includes是数组上的简单实例方法,并有助于轻松查找某个项是否在Array中(包括NaN不像indexOf) ...

  9. SQL Server 2012/2016/2017 新增函数

    /************************************************************** SQL Server 2012 新增的函数 ************** ...

随机推荐

  1. POJ2079:Triangle——题解

    http://poj.org/problem?id=2079 题目大意:求最大面积的三角形. —————————————————— 可以知道,最大面积的三角形的顶点一定是最大凸包的顶点. 接下来就是O ...

  2. bzoj2083: [Poi2010]Intelligence test(二分+vector)

    只是记录一下vector的用法 v.push_back(x)加入x v.pop_back()弹出最后一个元素 v[x]=v.back(),v.pop_back()删除x,但是会打乱vector顺序 v ...

  3. 【博弈论】Nim游戏

    百度百科 Definition 这样的游戏被称为Nim游戏: 1.有两个玩家,轮流进行操作 2.是公平游戏.即面对同一局面两个玩家所能进行的操作是相同的.例如中国象棋不是公平游戏.因为面对同一个局面, ...

  4. oracle 国外网站【转载】

    [转自]:http://www.2cto.com/database/201406/306615.html 1. http://www.oratechinfo.co.uk/ http://www.ora ...

  5. Javascript利用递归实现数组的快速排序

    // 定义快速排序方法 function quickSort(arr){ // 设置递归的终止条件 if( arr.length <= 1){ return arr; } // 获得数组arr的 ...

  6. hdu 3948 The Number of Palindromes

    The Number of Palindromes Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (J ...

  7. Codeforces 713C Sonya and Problem Wihtout a Legend DP

    C. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megaby ...

  8. 知问前端——Ajax表单插件

    传统的表单提交,需要多次跳转页面,极大的消耗资源也缺乏良好的用户体验.而这款form.js表单的Ajax提交插件将解决这个问题. 一.核心方法 官方网站:http://malsup.com/jquer ...

  9. 有趣的浏览器地址栏js代码

    1.编辑网页 在地址栏输入下面的代码按enter,网页上所有元素都能变成可编辑状态,你可以移动.调整元素大小.如果你只是讨厌某个网站想发泄一下,我建议你使用NetDisater. 代码如下: 程序代码 ...

  10. python模块subprocess学习

    当我们想要调用系统命令,可以使用os,commands还有subprocess模块整理如下: os模块: 1. os.system 输出命令结果到屏幕.返回命令执行状态. >>> o ...