POJ2599 A funny game (image game), poj2599funny
Question link: Portal
Question:
Given a chart, two people start from the starting point and fly in turn. When they leave this point, this point
You can't use it anymore. If it's your turn, you will lose if anyone can't fly.
It is difficult to find a failure. When a person is in the position s, there is no point that can be connected to this point.
It will be defeated. Then the data is small, and you can directly perform a brute-force search.
The Code is as follows:
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <set> # include <map> # include <queue> # define PB push_back # define MP make_pair # define REP (I, n) for (int I = 0; I <(n); ++ I) # define FOR (I, l, h) for (int I = (l ); I <= (h); ++ I) # define DWN (I, h, l) for (int I = (h); I> = (l); -- I) # define IFOR (I, h, l, v) for (int I = (h); I <= (l); I + = (v )) # define CLR (vis) memset (vis, 0, sizeof (vis) # define MST (vis, pos) memset (vis, pos, sizeof (vis) # define MAX3 (a, B, c) max (a, max (B, c )) # define MAX4 (a, B, c, d) max (a, B), max (c, d) # define MIN3 (a, B, c) min (a, min (B, c) # define MIN4 (a, B, c, d) min (a, B), min (c, d )) # define PI acos (-1.0) # define INF 1000000000 # define LINF extends limit 0000000000ll # define eps 1e-8 # define LL long longusing namespace std; const int maxn = 1001; int mp [maxn] [maxn]; bool vis [maxn]; int ans, n, s; B Ool dfs (int id) {FOR (I, 1, n) {if (mp [id] [I] &! Vis [I]) {// The Order of traversing the graph ensures that the answer is Min vis [id] = 1; if (! Dfs (I) {vis [id] = 0; ans = I; return true ;}} vis [id] = 0 ;}return false ;} int main () {while (~ Scanf ("% d", & n, & s) {CLR (mp); REP (I, n-1) {int u, v; scanf ("% d", & u, & v); mp [u] [v] = 1; mp [v] [u] = 1 ;} CLR (vis); if (dfs (s) printf ("First player wins flying to airport % d \ n", ans ); else puts ("First player loses");} return 0 ;}