NEERC 2016-2017 Probelm G. Game on Graph
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 GraphDescription
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的更多相关文章
- 【转】2016/2017 Web 开发者路线图
链接:知乎 [点击查看大图] 原图来自LearnCodeAcademy最火的视频,learncode是YouTube上最火的Web开发教学频道,介绍包括HTML/CSS/JavaScript/Subl ...
- Codeforces 1082 G - Petya and Graph
G - Petya and Graph 思路: 最大权闭合子图 对于每条边,如果它选了,那么它连的的两个点也要选 边权为正,点权为负,那么就是求最大权闭合子图 代码: #pragma GCC opti ...
- 2016湖南省赛----G - Parenthesis (括号匹配)
2016湖南省赛----G - Parenthesis (括号匹配) Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of lengt ...
- 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 ...
- ACM ICPC 2016–2017, NEERC, Northern Subregional Contest Problem J. Java2016
题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510 时间限制:2s 空间限制:256MB 题目大意: 给定一个数字c 用 " ...
- 2016 NEERC, Northern Subregional Contest G.Gangsters in Central City(LCA)
G.Gangsters in Central City 题意:一棵树,节点1为根,是水源.水顺着边流至叶子.该树的每个叶子上有房子.有q个询问,一种为房子u被强盗入侵,另一种为强盗撤离房子u.对于每个 ...
- [SinGuLaRiTy] COCI 2016~2017 #5
[SinGuLaRiTy-1012] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 最近神犇喜欢考COCI...... 测试题目 对于所有的 ...
- 关于ECMAScript 2016, 2017, 和2018中新增功能(摘抄)
ECMAScript 2016 1. Array.prototype.includes includes是数组上的简单实例方法,并有助于轻松查找某个项是否在Array中(包括NaN不像indexOf) ...
- SQL Server 2012/2016/2017 新增函数
/************************************************************** SQL Server 2012 新增的函数 ************** ...
随机推荐
- BZOJ1046 [HAOI2007]上升序列 【LIS + 字典序最小】
1046: [HAOI2007]上升序列 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 5410 Solved: 1877 [Submit][St ...
- AOJ.866 飞越原野 (三维BFS)
AOJ.866 飞越原野 (三维BFS) 题意分析 点我挑战题目 相比于普通的BFS,要多一维来记录当前剩余的体力.而且还要额外的一层循环来处理,飞过的路程. 代码总览 #include <io ...
- JS获取移动端系统信息(操作系统、操作系统版本、横竖屏状态、设备类型、网络状态、生成浏览器指纹)
function getOS() { // 获取当前操作系统 var os; if (navigator.userAgent.indexOf('Android') > -1 || navigat ...
- maven打包jar源码至私服
1. setting文件 配置私服中设置的用户和密码 <servers> <server> <id>releases</id> <username ...
- selenium - webdriver - Keys类(键盘操作)
Keys()类提供了键盘上几乎所有按键的方法,这个类可用来模拟键盘上的按键,包括各种组合键,如 Ctrl+A, Ctrl+X,Ctrl+C, Ctrl+V 等等 from selenium impor ...
- Codeforces Round #342 (Div. 2) B
B. War of the Corporations time limit per test 1 second memory limit per test 256 megabytes input st ...
- win7无法登陆linux samba共享
网上查了一下资料,总共有以下几种做法: 1.防火墙 2. Open the Run command and type "secpol.msc". Press "conti ...
- DEBUG宏
4.8.6.运算中的临时匿名变量4.8.6.1.C语言和汇编的区别(汇编完全对应机器操作,C对应逻辑操作)(1)C语言叫高级语言,汇编语言叫低级语言.(2)低级语言的意思是汇编语言和机器操作相对应,汇 ...
- UVA 11040 Add bricks in the wall
https://vjudge.net/problem/UVA-11040 找规律 #include<cstdio> using namespace std; ][]; int main() ...
- 删除windows上特定目录下以*.rar后缀名的python脚本
import os,fnmatch,datetime,time def all_files(root,pattern='*',single_level=False,yield_folders=Fals ...