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. GDI & GDI+

    GDI GDI绘图中的映射模式CDC::SetMapMode() GDI编程小结 GDI+ GDI+小例子 关于GDI+ GDI+编程小结

  2. bzoj1014: [JSOI2008]火星人prefix(splay+hash+二分)

    题目大意:一个字符串三个操作:①求两个后缀的LCP②插入一个字符③修改一个字符. 前几天刚学了hash+二分求lcp,就看到这题. 原来splay还能这么用?!原来splay模板这么好写?我以前写的s ...

  3. 四连测Day3

    题目链接:https://pan.baidu.com/s/1_vsHfMI_qO-9IDxmFLkHfg 密码: uza8 T1: 小奥的一笔画,判连通性,查奇偶点即可 #include<ios ...

  4. 2017-7-18-每日博客-关于Linux下的软链接和硬链接.doc

    ln命令 该命令在文件之间创建链接.这种操作实际上是给系统中已有的某个文件指定另外一个可用于访问它的名称.对于这个新的文件名,我们可以为之指定不同的访问权限,以控制对信息的共享和安全性的问题. 如果链 ...

  5. [sed]记录

    sed的括号本身没有特殊意义,如果要保留通配内容,需要转义. echo "1) host" |sed  's/1) ([a-z])/$1) $1/' 有两处有问题. 1. 首先是上 ...

  6. zigbee ---- 各种ID的作用

    EPAN ID的作用:

  7. PAT (Top Level)1002. Business DP/背包

    As the manager of your company, you have to carefully consider, for each project, the time taken to ...

  8. centos6.8+openvpn实现账户密码连接(通过端口映射的方式)

    #搭建openvpn(编译安装) 初始化环境 #update epel mirror yum install wget -y cd /etc/yum.repos.d && rm -rf ...

  9. 【BZOJ】1731: [Usaco2005 dec]Layout 排队布局

    [题意]给定按编号顺序站成一排的牛,给定一些约束条件如两牛距离不小于或不大于某个值,求1和n的最大距离.无解输出-1,无穷解输出-2. [算法]差分约束+最短路 [题解]图中有三个约束条件,依次分析: ...

  10. 20155335俞昆《java程序设计》第三周总结

    20155335  2006-2007-2  <Java程序设计>第三周学习总结 ##  教材学习内容总结 首先,关键是区基本类型和类类型,,产生对象必须定义类,类是一个概念,并不存在,对 ...