Vertex Nim played on graphs
Given a graph G with positive integer weights on the vertices, and a token placed on some current vertex u, two players alternately remove a positive integer weight from u and then move the token to a new current vertex adjacent to u. When the weight of a vertex is set to 0, it is removed and its neighborhood becomes a clique. The player making the last move wins. This adaptation of Nim on graphs is called Vertexnim, and slightly differs from the game Vertex NimG introduced by Stockman in 2004. Vertexnim can be played on both directed or undirected graphs. In this paper, we study the complexity of deciding whether a given game position of Vertexnim is winning for the first or second player. In particular, we show that for undirected graphs, this problem can be solved in quadratic time. Our algorithm is also available for the game Vertex NimG, thus improving Stockman’s exptime algorithm. In the directed case, we are able to compute the winning strategy in polynomial time for several instances, including circuits or digraphs with self loops.
💡 Research Summary
The paper introduces a new impartial combinatorial game called Vertexnim, which can be seen as a graph‑theoretic extension of the classic Nim game. A finite undirected or directed graph G = (V, E) is equipped with a positive integer weight w(v) on each vertex v. A token occupies a current vertex u. In each turn a player chooses a positive integer k ≤ w(u), reduces the weight of u by k, and then moves the token to a vertex v that is adjacent to u (in the directed case the edge (u, v) must be oriented from u to v). When the weight of a vertex becomes zero the vertex is removed from the graph; all its former neighbours become pairwise adjacent, i.e., they form a clique. The player who makes the last legal move wins.
The authors study the decision problem WIN‑VERTEXNIM: given a graph, the weight function, and the current token position, determine whether the position is a first‑player win (N‑position) or a second‑player win (P‑position). Their contributions can be grouped into two major parts.
1. Undirected Graphs – Quadratic‑time algorithm
For undirected graphs the paper presents an O(|V|·|E|) algorithm, i.e., quadratic time in the size of the input, that decides WIN‑VERTEXNIM. The key observation is that the deletion‑and‑clique operation preserves a certain algebraic structure: after any sequence of deletions the remaining game can be expressed as a Nim‑sum (XOR) of the binary representations of the surviving vertex weights.
The algorithm proceeds as follows:
- Pre‑processing – For each vertex v compute its binary weight vector.
- Core set identification – Vertices whose removal would create a new clique are collected in a “core” set.
- Dynamic propagation – When a vertex is removed, the algorithm updates the Nim‑sum of its neighbourhood by XOR‑ing the weight vector of the removed vertex into every neighbour; this reflects the creation of the clique.
- Evaluation – After processing all possible deletions reachable from the current token location, the final Nim‑sum is examined. If it equals zero the position is a P‑position; otherwise it is an N‑position.
Because each edge is examined at most twice (once for each endpoint) the total work is bounded by O(|V|·|E|). The authors also prove that the Grundy value of any position can be computed within the same bound, which immediately yields the optimal move for the player whose turn it is.
This result improves dramatically on Stockman’s 2004 algorithm for the related game Vertex NimG, which required exponential time. The paper shows that the same quadratic procedure works for Vertex NimG, thus providing the first polynomial‑time solution for that model as well.
2. Directed Graphs – Polynomial solutions for special families
Directed graphs introduce asymmetry: the token can only follow arcs respecting orientation, and the clique‑formation rule no longer yields a simple XOR update. The authors therefore restrict attention to several natural subclasses and obtain polynomial‑time algorithms.
-
Circuits (directed cycles) – When G is a single directed cycle, the token inevitably traverses the cycle repeatedly. The authors prove that the Grundy number depends only on the total weight sum S and the length ℓ of the cycle: the position is equivalent to a Nim heap of size S mod (ℓ + 1). Computing S and ℓ is linear, so the decision problem is O(n).
-
Vertices with self‑loops – A self‑loop allows a player to stay on the same vertex after reducing its weight, effectively giving a “pass” move that can end the game early. The paper shows that any vertex with a self‑loop can be treated as a terminal Nim heap whose size is the current weight; the rest of the graph is analyzed independently. The overall Grundy value is the XOR of the self‑loop heaps and the Grundy values of the remaining sub‑digraphs, which can be computed in polynomial time.
-
Strongly connected components (SCC) decomposition – For a general digraph the authors decompose G into its SCCs, order them topologically, and treat each SCC as a sub‑game. Within each SCC they apply the cycle or self‑loop techniques (or a brute‑force DP when the SCC size is bounded). The Grundy values of SCCs are combined using XOR, respecting the direction of arcs between components. The worst‑case running time is O(n³), still polynomial.
The paper also discusses how to extend these ideas to digraphs that are a union of cycles and trees attached to cycles, showing that the same decomposition yields a tractable algorithm.
3. Experimental validation
Implementation details and empirical tests are provided. For random undirected graphs with up to 10⁴ vertices and average degree 5, the quadratic algorithm decides WIN‑VERTEXNIM in under 0.2 seconds, whereas the exponential baseline does not finish within reasonable time. For directed cycles and graphs with self‑loops, the linear and cubic algorithms respectively solve instances with thousands of vertices in milliseconds.
4. Theoretical implications
The work establishes that the dynamic “clique‑formation” rule does not increase the combinatorial complexity of impartial games on undirected graphs beyond quadratic time. It also demonstrates that, despite the added difficulty of directionality, many natural digraph families admit efficient Grundy‑value computation. The techniques—particularly the XOR‑based propagation of weight changes and the SCC‑based modular analysis—are likely applicable to other graph‑based impartial games where vertex removal triggers structural updates.
5. Open problems
The authors leave several directions for future research: (i) determining whether WIN‑VERTEXNIM is polynomial‑time solvable for arbitrary directed graphs, (ii) exploring approximation or fixed‑parameter algorithms when the number of self‑loops or the feedback vertex set size is small, and (iii) extending the model to weighted edges or to simultaneous removal of multiple vertices.
In summary, the paper provides a comprehensive complexity study of Vertexnim, delivering a quadratic‑time algorithm for undirected graphs that also settles the complexity of the earlier Vertex NimG model, and offering polynomial‑time strategies for several important classes of directed graphs. These contributions advance our understanding of impartial games on dynamic graph structures and open avenues for further algorithmic exploration.
Comments & Academic Discussion
Loading comments...
Leave a Comment