UVALive-7042 the problem to make you Happy game

Source: Internet
Author: User

The main topic: give you a graph, Bob and Alice in the game, each round they take a step, when Bob and Alice at the same point or Bob no way to go, Bob lost, or Alice loses.

Idea: Because there is a ring when Bob wins, but when Bob loses the state is clear, we use Bob lose the state to win than the failure to deduce,

f[I [j] [K] indicates that Alice is in I, Bob is in J and Bob is going to lose or win.

#include <bits/stdc++.h>#defineLL Long Long#defineFi first#defineSe Second#defineMk Make_pair#definePII Pair<int, int>#defineY1 SKLDJFSKLDJG#defineY2 SKLDFJSKLEJGusing namespacestd;Const intN = -+7;Const intM = 1e5 +7;Const intINF =0x3f3f3f3f;ConstLL INF =0x3f3f3f3f3f3f3f3f;Const intMoD = 1e9 +7;intN, M, B, A, Deg[n], num[n][n][2];vector<int>Edge[n], redge[n];intf[n][n][2], vis[n][n][2];structNode {node (intXintYintd) { This->x =x;  This->y =y;  This->d =D; }    intx, Y, D;};voidinit () { for(inti =0; i < N; i++) {edge[i].clear (); Redge[i].clear (); } memset (deg,0,sizeof(deg)); memset (Vis,0,sizeof(VIS)); memset (num,0,sizeof(num));  for(inti =0; i < N; i++)         for(intj =0; J < N; J + +) f[i][j][0] = f[i][j][1] =1;}voidBFs () {Queue<node>que;  for(inti =1; I <= N; i++) {         for(intj =1; J <= N; J + +) {             for(intK =0; K <2; k++) {                if(i = =j) {F[i][j][k]=0;                    Que.push (Node (i, J, K)); VIS[I][J][K]=1; } Else if(k = =1) {                    if(!edge[j].size ()) {F[i][j][k]=0;                        Que.push (Node (i, J, K)); VIS[I][J][K]=1; }                }            }        }    }     while(!Que.empty ()) {Node cur=Que.front (); Que.pop (); if(!cur.d) { for(inti =0; I < redge[cur.y].size (); i++) {                intNxy =Redge[cur.y][i]; if(vis[cur.x][nxy][1])Continue; num[cur.x][nxy][1]++; if(num[cur.x][nxy][1] ==Deg[nxy]) {f[cur.x][nxy][1] =0; vis[cur.x][nxy][1] =1; Que.push (Node (cur.x, Nxy,1)); }            }        } Else {             for(inti =0; I < redge[cur.x].size (); i++) {                intNxx =Redge[cur.x][i]; if(vis[nxx][cur.y][0])Continue; f[nxx][cur.y][0] =0; vis[nxx][cur.y][0] =1; Que.push (Node (nxx, Cur.y,0)); }        }    }}intMain () {intT scanf"%d", &T);  for(intCAS =1; CAS <= T; cas++) {init (); scanf ("%d%d", &n, &m);  for(inti =1; I <= m; i++) {            intU, v; scanf"%d%d", &u, &v);            Edge[u].push_back (v);            Redge[v].push_back (U); Deg[u]++; } scanf ("%d%d", &b, &A);        BFS (); printf ("Case #%d:", CAs); printf ("%s\n", f[a][b][1] ?"Yes":"No"); }    return 0;}/**/

UVALive-7042 the problem to make you Happy game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.