Trail Making Game Hyun Sung Jun Jaehoon Kim Sang-il Oum Department of Mathematical Sciences KAIST, Daejeon, 305-701, Republic of Korea. May 7, 2009 Abstract Trail Making is a game played on a graph with a given initial vertex in which two players alternately choose an edge to lengthen a trail starting at the initial vertex. A player loses if he or she can not choose an edge to lengthen the trail. We provide the necessary and sufficient condition for a player to have a winning strategy on bipartite graphs. Furthermore, we prove that on the m n grid with one of the corner vertices as an initial vertex, the first player has a winning strategy if and only if m+1 and n+1 are relative prime. 1 Introduction We introduce Trail Making, a game played on a finite graph with a given initial vertex in which two players, say Alice and Bob, alternately choose an edge incident with the last vertex of the trail in order to lengthen the trail. A player loses if he or she can not choose an edge to extend the trail. We assume that Alice is the first player to choose an edge. Since a trail is a walk without repeated edges, players can not choose previously chosen edges. Trailing Making is a variant of Slither, invented by Silverman and discussed in two articles by Gardner in Scientific American [2, 3]. Slither is almost identical to Trail Making except that players choose an edge to lengthen a path instead of a trail. Originally Slither was a game on the grid but Anderson [1] extended it to general graphs and provided a general winning strategy based on perfect matchings of a graph. Trail Making may be regarded as a game-theoretic variation of searching Eulerian trails. It is easy to see that Bob can not lose Trail Making if the graph is bipartite and has an Eulerian trail starting at the initial vertex. jun0605@kaist.ac.kr mutual85@hotmail.com sangil@kaist.edu Supported by the SRC Program of Korea Science and Engineering Foundation (KOSEF) grant funded by the Korea government (MEST) (No. R11-2007-035-01002-0). 1
We now define a property of a set which will provide a sufficient condition to have a winning strategy. We allow graphs to have parallel edges or loops but all graphs in this paper are finite. A set of pairwise non-adjacent vertices having no loops is called independent. A trap of a graph G is an independent set S of vertices such that, for every vertex v in G, there are even number of edges joining v and S. Proposition 1. Bob has a winning strategy for Trail Making played on a graph G with an initial vertex v 0 if G has a trap containing v 0. Proof. Let T be a trap containing v 0. The strategy for Bob is to choose an edge incident with T. Since T is independent and every vertex out of T is incident with an even number of edges incident with T, Bob can always make his move. Therefore Bob can never lose with this strategy. Since G has finitely many edges, Bob wins. The converse of Proposition 1 does not hold in general. For example, let us consider the graph obtained by attaching, to an odd cycle C 2n+1, a new vertex v 0 adjacent to one of the vertices of the odd cycle. Then it is straightforward to verify that Bob always wins but no trap contains v 0. Nevertheless, in Section 2, we prove that the converse of Proposition 1 holds on bipartite graphs. In Section 3, we prove that when G is the m n grid (having mn vertices) and an initial vertex is one of the four corner vertices, Bob has a winning strategy if and only if m + 1 and n + 1 are not relative prime. 2 Strategy on bipartite graphs Let G be a bipartite graph with a bipartition A B = V (G). The bipartite adjacency matrix M = (m ab ) a A,b B of G is an A B matrix whose rows and columns are indexed by A and B, respectively, so that m ab is the number of edges joining a and b in G. We assume that M is a matrix over the binary field GF (2). Thus m ab = 1 if and only if there are odd number of edges joining a A and b B, and m ab = 0 otherwise. For an A B matrix M and subsets X, Y of A, B, respectively, we write M[X, Y ] to denote the submatrix of M by removing all rows not indexed by X and all columns not indexed by Y. Theorem 2. Let G be a bipartite graph and v 0 be a vertex of G. Then Bob has a winning strategy for Trail Making on G with an initial vertex v 0 if and only if G has a trap containing v 0. Proof. By Proposition 1, it is enough to prove that if G has no trap containing v 0, then Alice has a winning strategy. Let (A, B) be a bipartition of G. Let M be the bipartite adjacency matrix of G. We may assume that v 0 A and the first row of M is indexed by v 0. Since no trap containing v 0 exists, the row vector M[{v 0 }, B] is not spanned by the row vectors in M[A {v 0 }, B]. Thus rank(m) = rank(m[a {v 0 }, B]) + 1. We claim that there is a vector x = (x b ) b B such that Mx = (1, 0,..., 0) T. For proving this claim, we may assume that rank(m[a {v 0 }, B]) = A 1 by removing dependent rows in M[A {v 0 }, B] from M. We may also assume that B = A 2
by removing dependent columns of M because we can take x b = 0 if we remove b out of B. Then M is a nonsingular square matrix and therefore we obtain x = M 1 (1, 0,..., 0) T. This proves the claim. In other words, there exists a subset S of B such that there are an odd number of edges joining v 0 and S and for every vertex v in A except v 0, there are an even number of edges joining v and S. Let w be a vertex in S adjacent to v 0. Alice s first move is to take the edge e = v 0 w. We are now playing Trail Making on G \ e with the initial vertex w and S is a trap containing w and Bob is the first player to choose an edge in G \ e. Therefore by Proposition 1, Alice has a winning strategy. Theorem 2 provides the following corollary. Corollary 3. Let G be a bipartite graph with the bipartition A B = V (G). Let M be the bipartite adjacency matrix of G and let v 0 A. Then Bob has a winning strategy for Trail Making on G with an initial vertex v 0 if and only if rank(m) = rank(m[a {v 0 }, B]). 3 Strategy on grids For positive integers n and m, let G n,m be the n m grid, that is a graph on the vertex set {0, 1, 2,..., n 1} {0, 1, 2,..., m 1} such that two vertices (a, b) and (a, b ) are adjacent if and only if a a + b b = 1. As Slither was originally considered for grids, we solve Trail Making on grids. Theorem 4. Alice has a winning strategy in Trail Making on G n,m with an initial vertex (0, 0) if and only if n + 1 and m + 1 are relative prime. Let us now discuss the proof. For the inductive purpose, we may assume that Trail Making on G n,m with an initial vertex (0, 0) is a two-person game played on Z 2 with an initial vertex (0, 0) such that a player loses if he or she has no choice of unused edges to lengthen the trail, or he or she chooses an edge to move the end of the trail onto one of the following four lines: y = 1, x = 1, y = m, x = n. Lemma 5. Suppose that m n and while playing Trail Making, the end of the trail reaches the line y = m n for the first time. If it is the turn of a player X to lengthen the trail, then the other player Y has a winning strategy. Proof. We may assume that n 2. Let T be the trail from (0, 0) to (a, m n) such that all intermediate vertices are not on the line y = m n. We may assume that 0 a < n. Let e be the edge joining (a, m n) and (a, m n 1). Then either the last edge of T is e or m = n and T has no edges at all. Let S be a set of points (x, y) Z 2 satisfying the following (see Figure 1): a + m n x + y m + n 2 a, m n a y x m n + a x + y a + m n (mod 2). We observe that S is independent and every vertex (x, y) has an even number of neighbors in S if 0 x < n and 0 y < m except (x, y) = (a, m n 1). 3
(n a 1, m 1) (0, a + m n) (n 1, m a 1) Line y = m n e (a, m n) (0, 0) Figure 1: Construction of a trap in Lemma 5 when m = 13 and n = 7. Then S is a trap containing (a, m n) in G n,m \ E(T ) because no vertices of T except (a, m n) are neighbors of S in G n,m \ e. We may now regard the remaining game as Trail Making starting on G n,m \ E(T ) at the initial vertex (a, m n). Therefore the second player, Y, has a winning strategy by Proposition 1. Proof of Theorem 4. We proceed by induction on max(m, n). If m = n, then by Lemma 5, Bob has a winning strategy and gcd(m + 1, n + 1) = m + 1 1. Now we may assume that m > n. By Lemma 5, a player who moves the end of the trail to the line y = m n 1 for the first time will lose because the other player then can choose move the end of the trail to the line y = m n. Therefore both players should avoid moving the end of the trail onto the line y = m n 1 in order to win Trail Game on G n,m. Thus a player having a winning strategy on G n,m n 1 if and only if he or she has a winning strategy on G n,m. By induction, Alice has a winning strategy on G n,m n 1 if and only if gcd(n + 1, m n) = 1. Since gcd(n + 1, m + 1) = gcd(n + 1, m n), we conclude that Alice has a winning strategy on G n,m if and only if gcd(n + 1, m + 1) = 1. 4 Discussion In this paper we completely characterized who has a winning strategy for Trail Making on bipartite graphs and, we proved that the player having the winning strategy on the n m grid is determined by the greatest common divisor of m + 1 and n + 1. But we do not know whether or not there is a polynomial-time algorithm 4
to decide which player has a winning strategy on a non-bipartite graph. As we discussed in Section 1, the existence of a trap is not a necessary condition for Bob to have a winning strategy. Nevertheless, we remark that finding a trap in general is NP-hard, proved by Halldórsson et al. [4]. Acknowledgment. We would like to thank Tommy R. Jensen for the discussion, which provided the example in Section 1 on the converse of Proposition 1. References [1] W. N. Anderson, Jr. Maximum matching and the game of Slither. J. Combinatorial Theory Ser. B, 17:234 239, 1974. [2] M. Gardner. Mathematical games. Scientific American, 226:117 118, 1972. [3] M. Gardner. Mathematical games. Scientific American, 227:176 182, 1972. [4] M. M. Halldórsson, J. Kratochvíl, and J. A. Telle. Independent sets with domination constraints. Discrete Appl. Math., 99(1-3):39 54, 2000. 5