\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{xcolor}
\usepackage{tikz}
\usepackage{tikz-cd}

%\usepackage{systeme}

%\usepackage[textheight=8.5in, margin=1.6in]{geometry}
\usepackage[total={6in,8in}]{geometry}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\tikzstyle{ball} = [circle,shading=ball, ball color=black,
    minimum size=1mm,inner sep=1.3pt]
\tikzstyle{miniball} = [circle,shading=ball, ball color=black,
    minimum size=1mm,inner sep=0.5pt]
\tikzstyle{mminiball} = [circle,shading=ball, ball color=black,
    minimum size=0.6mm,inner sep=0.1pt]
\usetikzlibrary{arrows.meta}
\tikzset{>={Latex[length=2mm,width=1.5mm]}}
\tikzset{->-/.style={decoration={markings, mark=at position #1 with
  {\arrow{>}}},postaction={decorate}}}
\usetikzlibrary{decorations.pathmorphing}    
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{arrows.meta,calc}
\usetikzlibrary{bending}
\usetikzlibrary{decorations.markings,shapes.geometric}
\tikzset{->-/.style={decoration={markings, mark=at position #1 with
  {\arrow{>}}},postaction={decorate}}}
\tikzset{-|-/.style={decoration={markings, mark=at position #1 with
  {\arrow{stealth}}},postaction={decorate}}}
\tikzset{movearrow/.style 2 args ={
        decoration={markings,
	  mark= at position {#1} with {\arrow{#2}} ,
        },
        postaction={decorate}
    }
}

%\usepackage{graphicx}

\usepackage{needspace}  % <-- to prevent bad pagebreak over environment titles
% Use:  \Needspace{3\baselineskip} before opening an environment

\usepackage{enumitem}
%\setlist[enumerate]{leftmargin=*}

%\allowdisplaybreaks

%\usepackage[colorlinks=true,citecolor=black,linkcolor=black,urlcolor=blue]{hyperref}

\usepackage{algorithm}
\usepackage[noend]{algpseudocode}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\W}{\mathbb{W}}
\newcommand{\sn}{\mathfrak{S}}
\newcommand{\ve}{\varepsilon}
\newcommand{\ips}[2]{\langle{#1}, {#2}\rangle}
\newcommand{\incid}{\mathcal{I}(P)}
\newcommand{\tL}{\widetilde{L}}
\newcommand{\tV}{\widetilde{V}}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\Span}{\mathrm{Span}}
\DeclareMathOperator{\rk}{\mathrm{rank}}
\DeclareMathOperator{\wt}{\mathrm{wt}}
\DeclareMathOperator{\trace}{\mathrm{tr}}
\DeclareMathOperator{\im}{\mathrm{im}}
\DeclareMathOperator{\Sym}{\mathrm{Sym}}
\DeclareMathOperator{\Hom}{\mathrm{Hom}}
\DeclareMathOperator{\diag}{\mathrm{diag}}
\DeclareMathOperator{\glb}{\mathrm{glb}}
\DeclareMathOperator{\lub}{\mathrm{lub}}
\DeclareMathOperator{\Pic}{\mathrm{Pic}}
\DeclareMathOperator{\Jac}{\mathrm{Jac}}
\DeclareMathOperator{\cok}{\mathrm{cok}}
\DeclareMathOperator{\sgn}{\mathrm{sgn}}
\DeclareMathOperator{\outdeg}{\mathrm{outdeg}}

\parskip = 0.05in
\parindent = 0.0in

%\pagestyle{empty}

\begin{document}
\centerline{Math 372 lecture for Friday, Week 11}
\bigskip

\centerline{\bf A tree bijection}
\bigskip

Let $G=(V,E)$ be an undirected, loopless, connected multigraph, and let~$s\in V$
be designated as the {\em sink} vertex.  Let~$\tV:=V\setminus\left\{ s
\right\}$, the set of non-sink vertices.  A {\em sandpile configuration} on~$G$
is an element~$c\in\Z\tV$ and write~$c=\sum_{v\in\tV}c(v)v$ with~$c(v)\in \Z$
Given two configurations~$c,c'$, we write~$c\geq c'$ if~$c(v)\geq c'(v)$ for
all~$v\in\tV$.  In particular,~$c$ is {\em nonnegative} if~$c\geq0$, where~$0$
denotes the~$0$ configuration.  Fixing an ordering~$v_0,\dots,v_{n-1}$ of~$V$ and
taking~$s=v_0$, we have that~$\Z\tV\simeq\Z^{n-1}$ by identifying each
configuration~$c$ with the vector $c=(c_1,\dots,c_{n-1})$ where~$c_i:=c(v_i)$.  
The {\em degree} of a configuration is
\[
  \deg(c) =\sum_{v\in\tV}c(v)=\sum_{i=1}^{n-1}c_i.
\]

Let~$c$ be a configuration.  If~$v\in \tV$, we can {\em fire} or {\em
topple}~$v$ in~$c$ to get a new configuration~$c'$ by
\[
c' = c - \tL e_v
\]
where~$\tL$ is the reduced Laplacian of~$G$ with respect to~$v$ and~$e_v$ is
the~$v$-th standard basis vector.  This means that: (i) if~$w$ is a neighbor
of~$v$, then~$c'(w)=c(w)+a_{vw}$ where~$a_{vw}$ is the number of edges from~$v$
to~$w$, (ii) $c'(v)=c(v)-\deg_G(v)$, and (iii) $c'(w)=c(w)$, otherwise.
If~$S\subseteq\tV$, then we can perform a {\em set-firing} on~$c$ by toppling each
vertex in~$S$:
\[
  c' = c - \tL\text{\raisebox{1.8pt}{$\chi_S$}},
\]
where~$\chi_S$ is the indicator vector for the set~$S$ (so~$\chi_S(s)=1$ of
all~$s\in S$, and is~$0$, otherwise).

A {\em sandpile} is a nonnegative sandpile configuration, i.e., an
element~$c\in\N\tV$.  If~$c$ is a sandpile, and~$v\in\tV$, then
firing~$v$ in~$c$ is {\em legal} if the resulting configuration is a sandpile,
i.e., no vertex becomes negative after firing.  A set-firing by~$S\subseteq\tV$
is {\em legal} if the resulting configuration is a sandpile.  A sandpile is {\em
superstable} if it has no legal non-empty set-firings.
\medskip

One might think that to determine whether~$c$ is superstable, one would need to
check all~$2^{n-1}-1$ nonempty subsets of~$\tV$ to set whether any was legal.
However, the check can actually be done in at most~$n$ steps:

{\bf Dhar's algorithm.} Let~$c$ be a sandpile.  To determine if~$c$ is superstable,
start with~$S:=\tV$ and fire~$S$ to obtain the configuration~$c'$.
If~$c'\geq$, then~$S$ is a legal set-firing, and hence~$c$ is not superstable.
Otherwise, there exists~$v\in S$ such that~$c'(v)<0$.  Replace~$S$
by~$S\setminus\left\{ s \right\}$, and repeat: set-fire~$S$ on~$c$ to
obtain a new~$c'$.  If~$c'$ is a sandpile, then~$c$ is not superstable.  Otherwise,
there exists~$u\in S$ such that~$c'(u)<0$.  Remove~$u$ from~$S$, etc.  In the
end, we either find a legal non-empty set firing, or~$S=\emptyset$, in which
case~$c$ is superstable.

Recall the isomorphism
\begin{align*}
  \Jac(G)&\xrightarrow{\sim}\Z^{n-1}/\im(\tL)\\
  (c_0,\dots,c_{n-1})&\mapsto(c_1,\dots,c_{n-1})
\end{align*}
\medskip

{\bf Theorem.} There is exactly one superstable sandpile in each equivalence class
of~$\Z^{n-1}$ modulo the image of~$\tL$.  Thus, the superstables form a complete
set of distinct representatives for the elements of~$\Jac(G)$.
Let $\mathrm{Sp}(G)$ denote the set of superstable elements of~$G$.  Define the
sum of superstables~$c$ and~$c'$ to be the superstablization of~$c+c'$.  This
turns~$\mathrm{Sp}(G)$ into a group isomorphic to~$\Jac(G)$.
\medskip

{\bf Example.} Consider the configuration~$c=(2,0,1)$ on {\em diamond graph}~$G$:
\begin{center}
\begin{tikzpicture}[scale=0.5]
  \node[ball,label={below:$s$}] (s) at (0,-1.732) {};
  \node[ball,label={left:$v_1$}] (1) at (-1,0) {};
  \node[ball,label={right:$v_2$}] (2) at (1,0) {};
  \node[ball,label={above:$v_3$}] (3) at (0,1.732) {};
  \draw (s)--(1)--(3)--(2)--(s);
  \draw (1)--(2);
  \node at (0,-3.5) {$G$};
  \begin{scope}[xshift=7cm]
    \node[ball,label={below:$s$}] (s) at (0,-1.732) {};
    \node[ball,label={left:$2$}] (1) at (-1,0) {};
    \node[ball,label={right:$0$}] (2) at (1,0) {};
    \node[ball,label={above:$1$}] (3) at (0,1.732) {};
    \draw (s)--(1)--(3)--(2)--(s);
    \draw (1)--(2);
    \node at (0,-3.5) {$c$};
  \end{scope}
\end{tikzpicture}
\end{center}
Apply Dhar's algorithm to see if~$c$ is superstable.  Firing the set~$S=\tV$
yields the configuration~$c'=(1,-1,1)$ for which~$c'(v_2)=-1<0$.  So
let~$S=\tV\setminus\left\{ v_2 \right\}=\left\{ v_1,v_3 \right\}$.
Firing~$S$ on~$c$ now yields~$c'=(0,2,0)\geq0$. So we have found a non-empty
legal set-firing for~$c$.  Therefore,~$c$ is not superstable.  However, one may
now check that~$(0,2,0)$ {\em is} superstable.  Since set-firing changes a
configuration by subtracting an element of~$\im(\tL)$, it does not change the
configuration's equivalence class modulu~$\im(\tL)$.  Thus, for
example~$(2,0,1)=(0,2,0)$ in~$\Jac(G)$, i.e.,~$(0,2,0)$ is the superstable
representative of~$(2,0,1))$ in~$\Jac(G)$.
\medskip

{\bf Example.}  For the diamond graph, above, we have~$|\Jac(G)|=\det(\tL)=8$.
Find the eight superstable elements on~$G$.  In fact,~$\Jac(G)\simeq\Z/8\Z$.
Find a superstable generator for~$\Jac(G)$.
\medskip

{\bf Depth-first search tree bijection and tree inversions.}  By the matrix-tree
theorem, the number of elements of~$\Jac(G)$ is the number of spanning trees
of~$G$, and by the theorem, above, the superstables serve as a complete set of
representatives for~$\Jac(G)$.  We will now describe a bijection between
superstables and spanning trees.  This bijection will have the further property
that the degree of the superstable will be related to a statistic for the
corresponding tree called the {\em inversion number}.

In the following we  will refer to our vertices by their indices.  So vertex~$j$
means~$v_j$.  To describe our tree-bijection, take a superstable
configuration~$c$ and think of it as an assignment of firefighters to vertices.
We think of the edges and vertices as being made of a flammable material,
perhaps wood.  Light the sink vertex on fire and let is spread along edges a
controlled manner, which we will now describe, burning one edge at a time.  The spreading is determined by a
{\em depth-first search} of the vertices of~$G$.  In detail: at the beginning of
each step of the algorithm, there will be a currently {\em active} burnt
vertex~$i$ (initially~$i=s$).  To find the next edge to burn, find the maximal
(in numerical order) vertex~$j$ such that: (i)~$j$ is unburnt, and (ii)~$\left\{
i,j \right\}$ is an unburnt edge.  (We consider the case there is no such~$j$
below.)  Burn the edge~$e:=\left\{ i,j \right\}$.  If the number of burnt edges
incident on~$j$ is now greater than~$c(j)$, then the firefighters at~$j$ are
overwhelmed and abandon the vertex.  In that case,~$e$ is added to the tree we
are constructing, and~$j$ is burnt, becoming the active vertex for the next step
in the algorithm.  If not, the next step of the algorithm proceeds with~$i$
again the active vertex.

If there are no vertices~$j$ adjacent to~$i$ meeting the two criteria specified
above, the algorithm proceeds by recursively backtracking: the vertex~$i'\neq i$ that
was active just before~$i$ became active is set as the active vertex,
and the algorithm proceeds as before.  (The vertex~$i'$ will be the unique vertex
adjacent to~$i$ in the tree built so far.)

In any event, the algorithm halts as soon as all vertices are burnt, returning a
spanning tree of~$G$.  A precise description is provided in Algorithm~\ref{alg:
dfs}, displayed below.
{
\small
\begin{algorithm}[ht]
\caption{ {\bf Depth-first search burning algorithm}.}\label{alg: dfs}
\begin{algorithmic}[1]
  \State {{\sc input:} \newline
    \text{\ \ \ \ $G=(V,E)$} -- simple undirected graph with~$V=\left\{
      0,\dots,n\right\}$\newline
  \text{\ \ \ \ $s\in V$} -- sink vertex\newline
\text{\ \ \ \ $c\in\N\tV$} -- sandpile on~$G$ with respect to~$s$ }
\State {\sc output:} {\tt tree} -- tree of~$G$, a spanning tree iff~$c$ is
superstable
  \State {\bf initialization:}\newline
   $\text{\ \ {\tt burnt\_vertices}} = \left\{ s \right\}$,
   $\text{\ \ {\tt burnt\_edges}} = \emptyset$,
   $\text{\ \ \ \ {\tt tree}} = \emptyset$
   \State {\bf execute} {\sc dfs\_from}($s$)
   \State {\bf return} {\tt tree}
   \Statex \rule{0.5\textwidth}{.4pt}
   \Statex{\sc dfs\_from}
    \Function{\sc dfs\_from}{$i$} 
      \ForAll{$j$ adjacent to $i$ in $G$, from largest numerical value to smallest}
      \If{$j\notin\text{\tt burnt\_vertices}$}
	  \If{$c(j)=0$}
	  \State append $j$ to {\tt burnt\_vertices}
	  \State append $(i,j)$ to {\tt tree}
	    \State {\sc dfs\_from}$(j)$
	  \Else
	     \State $c(j) = c(j)-1$
	     \State append $(i,j)$ to {\tt burnt\_edges}
	  \EndIf
       \EndIf	
     \EndFor
   \EndFunction
  \end{algorithmic}
\end{algorithm}
}
\medskip

{\bf Example.}
  Figure~\ref{fig: dfs k5} considers the depth-first search algorithm for the
  superstable~$c=(1,0,2,1)$ on the complete graph~$K_5$.  The graph and its
  vertex labels appear in the bottom right of the figure. The sink vertex,~$0$,
  is lit and its neighbors are probed in reverse numerical order.  Firefighters
  protect vertices~$4$ and~$3$, but there are none at vertex~$2$. So the edges
  connecting~$0$ to these vertices are burnt.  The vertex~$2$ is burnt and the
  edge~$\left\{ 0,2 \right\}$ becomes part of the tree. Vertex~$2$ becomes the
  active vertex, and the algorithm continues. 

  The largest unburnt neighbor of~$2$ is vertex~$4$, and the single firefighter at
  vertex~$4$ is already occupied with the burnt edge~$\left\{ 0,4 \right\}$.  So
  that firefighter is overwhelmed.  The edge~$\left\{ 2,4 \right\}$
  is burnt and added to the tree.  The vertex~$4$ is newly burnt and becomes the
  active vertex.  
\begin{figure}[ht]
  \centering
  \begin{tikzpicture}[scale=0.3]
    \def\rad{2.5}
    \def\myrad{2.5mm}
    \begin{scope}
      \node[ball] (0) at (-90:\rad) {};
      \node[ball,label={below right:$1$}] (1) at (-90+72:\rad) {};
      \node[ball,label={above right:$0$}] (2) at (-90+2*72:\rad) {};
      \node[ball,label={above left:$2$}] (3) at (-90+3*72:\rad) {};
      \node[ball,label={below left:$1$}] (4) at (-90+4*72:\rad) {};
      \foreach \i in {1,2,3,4}
        \foreach \j in {0,...,\i} {
	  \draw (\i)--(\j);
	}
	\draw[gray,ultra thick] (-0.28,-0.02-2.75) rectangle (0.25,0.52-2.75);
      \draw[thick] (4.2,0.5) edge[-latex,bend left=10,black] (5.8,0.5);
    \end{scope}
    \begin{scope}[xshift=10cm]
      \node[ball] (0) at (-90:\rad) {};
      \node[ball,label={right:$1$}] (1) at (-90+72:\rad) {};
      \node[ball,label={right:$0$}] (2) at (-90+2*72:\rad) {};
      \node[ball,label={left:$2$}] (3) at (-90+3*72:\rad) {};
      \node[ball,label={left:$1$}] (4) at (-90+4*72:\rad) {};
      \draw (0)--(1);
      \draw[ultra thick, gray] (0)--(2);
      \draw[ultra thick, densely dotted, gray] (0)--(3);
      \draw[ultra thick, densely dotted, gray] (0)--(4);
      \draw (1)--(2);
      \draw (1)--(3);
      \draw (1)--(4);
      \draw (2)--(3);
      \draw (2)--(4);
      \draw (3)--(4);
      \fill[gray, draw=gray] (0) circle (\myrad);
      \draw[gray, ultra thick] (-0.28+1.48,-0.02+1.77) rectangle (0.25+1.48,0.52+1.77);
      \draw[thick] (4.2,0.5) edge[-latex,bend left=10,black] (5.8,0.5);
    \end{scope}
    \begin{scope}[xshift=20cm]
      \node[ball] (0) at (-90:\rad) {};
      \node[ball,label={right:$1$}] (1) at (-90+72:\rad) {};
      \node[ball,label={right:$0$}] (2) at (-90+2*72:\rad) {};
      \node[ball,label={left:$2$}] (3) at (-90+3*72:\rad) {};
      \node[miniball,label={left:$1$}] (4) at (-90+4*72:\rad) {};
      \draw (0)--(1);
      \draw[ultra thick, gray] (0)--(2);
      \draw[ultra thick, densely dotted, gray] (0)--(3);
      \draw[ultra thick, densely dotted, gray] (0)--(4);
      \draw (1)--(2);
      \draw (1)--(3);
      \draw (1)--(4);
      \draw (2)--(3);
      \draw[ultra thick, gray] (2)--(4);
      \draw (3)--(4);
      \fill[gray, draw=gray] (0) circle (\myrad);
      \fill[gray, draw=gray] (2) circle (\myrad);
      \draw[gray, ultra thick] (-0.28-2.37,-0.02-1.02) rectangle (0.25-2.37,0.52-1.02);
      \draw[thick] (4.2,0.5) edge[-latex,bend left=10,black] (5.8,0.5);
    \end{scope}
    \begin{scope}[xshift=30cm]
      \node[ball] (0) at (-90:\rad) {};
      \node[ball,label={right:$1$}] (1) at (-90+72:\rad) {};
      \node[ball,label={right:$0$}] (2) at (-90+2*72:\rad) {};
      \node[ball,label={left:$2$}] (3) at (-90+3*72:\rad) {};
      \node[miniball,label={left:$1$}] (4) at (-90+4*72:\rad) {};
      \draw (0)--(1);
      \draw[ultra thick, gray] (0)--(2);
      \draw[ultra thick, densely dotted, gray] (0)--(3);
      \draw[ultra thick, densely dotted, gray] (0)--(4);
      \draw (1)--(2);
      \draw (1)--(3);
      \draw[ultra thick, densely dotted, gray] (1)--(4);
      \draw (2)--(3);
      \draw[ultra thick, gray] (2)--(4);
      \draw[ultra thick, densely dotted, gray] (3)--(4);
      \fill[gray, draw=gray] (0) circle (\myrad);
      \fill[gray, draw=gray] (4) circle (\myrad);
      \draw[gray, ultra thick] (-0.28+1.48,-0.02+1.77) rectangle (0.25+1.48,0.52+1.77);
    \end{scope}
    \begin{scope}[xshift=5cm,yshift=-10cm]
      \draw[thick] (4.2-10,0.5) edge[-latex,bend left=10,black] (5.8-10,0.5);
      \node[ball] (0) at (-90:\rad) {};
      \node[ball,label={right:$1$}] (1) at (-90+72:\rad) {};
      \node[ball,label={right:$0$}] (2) at (-90+2*72:\rad) {};
      \node[ball,label={left:$2$}] (3) at (-90+3*72:\rad) {};
      \node[miniball,label={left:$1$}] (4) at (-90+4*72:\rad) {};
      \draw (0)--(1);
      \draw[ultra thick, gray] (0)--(2);
      \draw[ultra thick, densely dotted, gray] (0)--(3);
      \draw[ultra thick, densely dotted, gray] (0)--(4);
      \draw (1)--(2);
      \draw (1)--(3);
      \draw[ultra thick, densely dotted, gray] (1)--(4);
      \draw[ultra thick, gray] (2)--(3);
      \draw[ultra thick, gray] (2)--(4);
      \draw[ultra thick, densely dotted, gray] (3)--(4);
      \fill[gray, draw=gray] (0) circle (\myrad);
      \fill[gray, draw=gray] (2) circle (\myrad);
      \fill[gray, draw=gray] (4) circle (\myrad);
      \draw[gray, ultra thick] (-0.28-1.46,-0.02+1.77) rectangle (0.25-1.46,0.52+1.77);
      \draw[thick] (4.2,0.5) edge[-latex,bend left=10,black] (5.8,0.5);
    \end{scope}
    \begin{scope}[xshift=15cm,yshift=-10cm]
      \draw[thick] (4.2-10,0.5) edge[-latex,bend left=10,black] (5.8-10,0.5);
      \node[ball] (0) at (-90:\rad) {};
      \node[ball,label={right:$1$}] (1) at (-90+72:\rad) {};
      \node[ball,label={right:$0$}] (2) at (-90+2*72:\rad) {};
      \node[ball,label={left:$2$}] (3) at (-90+3*72:\rad) {};
      \node[miniball,label={left:$1$}] (4) at (-90+4*72:\rad) {};
      \draw (0)--(1);
      \draw[ultra thick, gray] (0)--(2);
      \draw[ultra thick, densely dotted, gray] (0)--(3);
      \draw[ultra thick, densely dotted, gray] (0)--(4);
      \draw (1)--(2);
      \draw[ultra thick, gray] (1)--(3);
      \draw[ultra thick, densely dotted, gray] (1)--(4);
      \draw[ultra thick, gray] (2)--(3);
      \draw[ultra thick, gray] (2)--(4);
      \draw[ultra thick, densely dotted, gray] (3)--(4);
      \fill[gray, draw=gray] (0) circle (\myrad);
      \fill[gray, draw=gray] (2) circle (\myrad);
      \fill[gray, draw=gray] (3) circle (\myrad);
      \fill[gray, draw=gray] (4) circle (\myrad);
      \draw[gray, ultra thick] (-0.28+2.39,-0.02-1.02) rectangle (0.25+2.39,0.52-1.02);
    \end{scope}
    \begin{scope}[xshift=27cm,yshift=-10cm]
      \node[circle,inner sep=2pt, minimum size=0pt,draw] (0) at (-90:\rad) {$0$};
      \node[circle,inner sep=2pt, minimum size=0pt,draw] (1) at (-90+72:\rad) {$1$};
      \node[circle,inner sep=2pt, minimum size=0pt,draw] (2) at (-90+2*72:\rad) {$2$};
      \node[circle,inner sep=2pt, minimum size=0pt,draw] (3) at (-90+3*72:\rad) {$3$};
      \node[circle,inner sep=2pt, minimum size=0pt,draw] (4) at (-90+4*72:\rad) {$4$};
      \foreach \i in {1,2,3,4}
        \foreach \j in {0,...,\i} {
	  \draw (\i)--(\j);
	}
      \node at (-1,-5) {$K_5$};
    \end{scope}
\end{tikzpicture}
\caption{The depth-first search algorithm for the superstable~$c=(1,0,2,1)$
  on~$K_5$. The gray rectangle marks the active
vertex, all gray edges are burnt, and solid gray edges are tree-edges.}\label{fig: dfs k5}
\end{figure}
  The unburnt edges joining~$4$ to unburnt neighbors
  are~$\left\{ 3,4 \right\}$ and~$\left\{ 1,4 \right\}$.  There are sufficient
  firefighters to protect vertices~$1$ and~$3$.  So these edges are burnt but
  not vertices~$1$ and~$3$.  We then backtrack: vertex~$2$ again becomes the
  active vertex, and the algorithm continues from there to completion.  In the
  figure, the edges of the resulting spanning tree are shown in solid red.
  Dotted red edges are edges that were burnt but did not become part of the
  tree.    
\medskip

{\bf Tree inversions.}  Let~$T$ be a tree with vertices~$V=\left\{
0,\dots,n \right\}$, and pick a root/sink vertex~$s\in V$.  If~$i,j\in V$
and~$i$ is on the unique path from~$j$ to~$s$, then~$i$ is an {\em
ancestor} of~$j$, and~$j$ is a {\em descendant} if~$i$.  If~$i$ is an ancestor
of~$j$ and~$\{i,j\}$ is an edge of~$T$, we say~$i$ is the {\em parent}
of~$j$ and~$j$ is a child of~$i$.  Each non-root vertex of~$T$ has a unique
parent, but vertices may have many children.  

{\bf Definition}  An {\em inversion} of the rooted tree~$T$ is an ordered
  pair~$(i,j)$ of vertices such that: (i)~$i>j$, (ii)~$i$ is not the root
  vertex\footnote{We will usually choose~$0$ as the root vertex, in which case
  condition~(i) implies~condition~(ii).}, and (iii)~$i$ is an ancestor of~$j$.
  The number of inversions of~$T$ is the {\em inversion number}
  for~$T$.
\medskip

{\bf Example.}
  In Figure~\ref{fig: dfs k5}, the depth-first burning algorithm produces the
  following tree rooted at vertex~$0$:
  \begin{center}
    \begin{tikzpicture}[scale=0.6]
      \node[mminiball,label={below:$0$}] (0) at (0,0) {};
      \node[mminiball,label={left:$2$}] (2) at (0,1) {};
      \node[mminiball,label={left:$3$}] (3) at (-0.866,2) {};
      \node[mminiball,label={right:$4$}] (4) at (0.866,2) {};
      \node[mminiball,label={left:$1$}] (1) at (-0.866,3) {};
      \draw (0)--(2)--(3)--(1);
      \draw (2)--(4);
    \end{tikzpicture}
  \end{center}
  This tree has two inversions,~$(2,1)$ and~$(3,1)$, so its inversion number
  is~$2$.
\medskip

{\bf Exercise.}
  \begin{enumerate}
    \item Find all sixteen trees with vertices~$\left\{ 0,1,2,3 \right\}$, or
      equivalently, the sixteen spanning trees of the complete graph~$K_4$ on
      this vertex set.    
    \item Describe the sixteen superstable sandpiles on~$K_4$.    
    \item Let~$\tau_k$ denote the number of these trees with inversion
      number~$k$, and let~$h_k$ denote the number of superstables on~$K_4$ with
      degree~$k$.  Verify the following table:
      \[
    \begin{array}{c|cccc}
      k&0&1&2&3\\\hline
      \tau_k&6&6&3&1\\
      h_k&1&3&6&6
    \end{array}\quad.
  \]
  \end{enumerate}
\medskip

Note that the inversion and degree counts in the table in Exercise are the same
but in reverse order.  This is indicative of a general phenomenon first proved
by Kreweras: Let~$g=n(n-1)/2$, the genus (cycle rank) of the complete graph~$K_{n+1}$.
Let~$\tau_k$ denote the number of spanning trees on~$V=\left\{ 0,\dots,n
\right\}$ with inversion number~$k$, and let~$h_k$ be the number of superstables
on ~$K_{n+1}$ of degree~$k$.  Then,
\begin{equation} \label{eqn: kreweras}
\tau_k=h_{g-k}
\end{equation}
for~$0\leq k\leq g$.

To try to generalize Kreweras' formula, fix an arbitrary graph~$G$ of the type
considered in this section.  Let~$\tau_k$ be its number of spanning trees with
inversion number~$k$, let~$h_k$ be the number of superstables of~$G$ with
degree~$k$, and let~$g:=|E|-|V|+1$ be its {\em genus} (or cycle rank).  It turns
out that it is {\em sometimes} the case that equation~\eqref{eqn:  kreweras}
continues to hold, but not always.  For a case where it does not hold consider
the house graph as pictured in Figure~\ref{fig: dfs house graph} with its~$11$
spanning trees. The genus of the house graph is~$2$.  The inversion numbers and
degree counts for this graph are:
\[
  \begin{array}{c|cccc}
    k&0&1&2&3\\\hline
    \tau_k&4&3&3&1\\
    h_k&1&4&6&0\\
  \end{array}\quad.
\]
The problem is that our notion of an inversion of a spanning tree does not take into
account the structure of~$G$.  The appropriate generalization is:
\medskip

{\bf Definition}\label{def: kappa inversion} Let~$G$ be a graph (simple,
  connected, undirected, with the vertex set~$\left\{ 0,\dots,n \right\}$ and
fixed root/sink vertex~$s$), and let~$T$ be a spanning tree rooted at~$s$.  An
inversion~$(i,j)$ of~$T$ is a~\emph{$\kappa$-inversion} if the parent of~$i$ is
adjacent to~$j$ in~$G$.  The~{\em $\kappa$-inversion
number},~$\kappa(T)=\kappa(G,T)$, is the number of~$\kappa$-inversions of~$T$.
\medskip

% the spanning tree of the house graph and their k-inversion numbers
\begin{figure}[ht]
  \centering
\begin{tikzpicture}[scale=0.6]
  \def\rad{1pt}
  \draw[fill] (0,-3) circle [radius=\rad];
  \draw[fill] (-0.8,-2) circle [radius=\rad];
  \draw[fill] (-0.8,-1) circle [radius=\rad];
  \draw[fill] (-0.8,0) circle [radius=\rad];
  \draw[fill] (0.8,-2) circle [radius=\rad];
  \draw (0,-3) node[below]{$0$} --
        (-0.8,-2) node[left]{$1$} --
        (-0.8,-1) node[left]{$3$} --
        (-0.8,0) node[left]{$4$}
        (0,-3)  -- (0.8,-2) node[right]{$2$};
  \node at (0,-4.8){$\kappa=0$};
  \node  at (0,-5.6){$(0,0,1,1)$};
\end{tikzpicture}
\hspace{1 mm}
\begin{tikzpicture}[scale=0.6]
  \def\rad{1pt}
  \draw[fill] (0,-3) circle [radius=\rad];
  \draw[fill] (-0.8,-2) circle [radius=\rad];
  \draw[fill] (0.8,-2) circle [radius=\rad];
  \draw[fill] (0,-3) circle [radius=\rad];
  \draw[fill] (1.6,-1) circle [radius=\rad];
  \draw (1.3,-2) node {$2$};
  \draw (0,-3) node[below]{$0$} -- (-0.8,-2) node[left]{$1$}
  (0,-3)  -- (0.8,-2)
	-- (0,-1) node[left]{$3$}
        (0.8,-2)  -- (1.6,-1) node[right]{$4$};
  \node at (0,-4.8){$\kappa=0$};
  \node  at (0,-5.6){$(1,0,1,0)$};
\end{tikzpicture}
\hspace{1 mm}
\begin{tikzpicture}[scale=0.6]
  \def\rad{1pt}
  \draw[fill] (0,-3) circle [radius=\rad];
  \draw[fill] (-0.8,-2) circle [radius=\rad];
  \draw[fill] (0.8,-2) circle [radius=\rad];
  \draw[fill] (0.8,-1) circle [radius=\rad];
  \draw[fill] (0.8,0) circle [radius=\rad];
  \draw (0,-3) node[below]{$0$} -- (-0.8,-2) node[left]{$1$}
        (0,-3) -- (0.8,-2) node[right]{$2$} --
        (0.8,-1) node[right]{$3$} -- (0.8,0) node[right]{$4$};
  \node at (0,-4.8){$\kappa=0$};
  \node  at (0,-5.6){$(1,0,0,1)$};
\end{tikzpicture}
\hspace{1 mm}
\begin{tikzpicture}[scale=0.6]
  \def\rad{1pt}
  \draw[fill] (0,-3) circle [radius=\rad];
  \draw[fill] (0,-2) circle [radius=\rad];
  \draw[fill] (0,-1) circle [radius=\rad];
  \draw[fill] (0,0) circle [radius=\rad];
  \draw[fill] (0,1) circle [radius=\rad];
  \draw (0,-3) node[below]{$0$} --
        (0,-2) node[left]{$1$} --
        (0,-1) node[left]{$3$} --
        (0,0) node[left]{$2$} --
        (0,1) node[left]{$4$};
  \node at (0,-4.8){$\kappa=0$};
  \node  at (0,-5.6){$(0,1,0,1)$};
\end{tikzpicture}
\begin{tikzpicture}[scale=0.6]
  \def\rad{1pt}
  \draw[fill] (0,-3) circle [radius=\rad];
  \draw[fill] (0,-2) circle [radius=\rad];
  \draw[fill] (0,-1) circle [radius=\rad];
  \draw[fill] (-0.8,0) circle [radius=\rad];
  \draw[fill] (0.8,0) circle [radius=\rad];
  \draw (-0.5,-1) node {$3$};
  \draw (0,-3) node[below]{$0$} -- (0,-2) node[left]{$1$} -- 
  (0,-1) 
  -- (-0.8,0) node[left]{$2$}
        (0,-1)  -- (0.8,0) node[right]{$4$};
  \node at (0,-4.8){$\kappa=0$};
  \node  at (0,-5.6){$(0,2,0,0)$};
\end{tikzpicture}
\hspace{1 mm}
\begin{tikzpicture}[scale=0.6]
  \def\rad{1pt}
  \draw[fill] (0,-3) circle [radius=\rad];
  \draw[fill] (-0.8,-2) circle [radius=\rad];
  \draw[fill] (-0.8,-1) circle [radius=\rad];
  \draw[fill] (0.8,-2) circle [radius=\rad];
  \draw[fill] (0.8,-1) circle [radius=\rad];
  \draw (0,-3) node[below]{$0$} -- (-0.8,-2) node[left]{$1$} -- (-0.8,-1) node[left]{$3$}
        (0,-3)  -- (0.8,-2) node[right]{$2$} -- (0.8,-1) node[right]{$4$};
  \node at (0,-4.8){$\kappa=0$};
  \node  at (0,-5.6){$(0,0,2,0)$};
\end{tikzpicture}
\vskip10mm
\begin{tikzpicture}[scale=0.6]
  \def\rad{1pt}
  \draw[fill] (0,-3) circle [radius=\rad];
  \draw[fill] (0,-2) circle [radius=\rad];
  \draw[fill] (0,-1) circle [radius=\rad];
  \draw[fill] (-0.8,0) circle [radius=\rad];
  \draw[fill] (0.8,0) circle [radius=\rad];
  \draw	(-0.5,-1) node {$3$};
  \draw (0,-3) node[below]{$0$} --
        (0,-2) node[left]{$2$} --
	(0,-1)  --
        (-0.8,0) node[left]{$1$}
        (0,-1)--(0.8,0) node[right]{$4$};
  \node at (0,-4.8){$\kappa=1$};
  \node  at (0,-5.6){$(0,0,0,1)$};
\end{tikzpicture}
\hspace{1mm}
\begin{tikzpicture}[scale=0.6]
  \def\rad{1pt}
  \draw[fill] (0,-3) circle [radius=\rad];
  \draw[fill] (0,-2) circle [radius=\rad];
  \draw[fill] (-0.8,-1) circle [radius=\rad];
  \draw[fill] (-0.8,0) circle [radius=\rad];
  \draw[fill] (0.8,-1) circle [radius=\rad];
  \draw (-0.5,-2) node {$2$};
  \draw (0,-3) node[below]{$0$} -- (0,-2) 
  -- (0.8,-1) node[right]{$4$} (0,-2) 
  -- (-0.8,-1) node[left]{$3$} (-0.8,-1) 
  -- (-0.8,0) node[left]{$1$}; 
  \node at (0,-4.8){$\kappa=1$};
  \node  at (0,-5.6){$(0,0,1,0)$};
\end{tikzpicture}
\hspace{1 mm}
\begin{tikzpicture}[scale=0.6]
  \def\rad{1pt}
  \draw[fill] (0,-3) circle [radius=\rad];
  \draw[fill] (0,-2) circle [radius=\rad];
  \draw[fill] (0,-1) circle [radius=\rad];
  \draw[fill] (0,0) circle [radius=\rad];
  \draw[fill] (0,1) circle [radius=\rad];
  \draw (0,-3) node[below]{$0$} --
        (0,-2) node[left]{$1$} --
        (0,-1) node[left]{$3$} --
        (0,0) node[left]{$4$} --
        (0,1) node[left]{$2$};
  \node at (0,-4.8){$\kappa=1$};
  \node  at (0,-5.6){$(0,1,0,0)$};
\end{tikzpicture}
\hspace{1 mm}
\begin{tikzpicture}[scale=0.6]
  \def\rad{1pt}
  \draw[fill] (0,-3) circle [radius=\rad];
  \draw[fill] (-0.8,-2) circle [radius=\rad];
  \draw[fill] (0.8,-2) circle [radius=\rad];
  \draw[fill] (0.8,-1) circle [radius=\rad];
  \draw[fill] (0.8,0) circle [radius=\rad];
  \draw (0,-3) node[below]{$0$} --
        (0.8,-2) node[right]{$2$} -- (0.8,-1) node[right]{$4$} -- (0.8,0) node[right]{$3$}
        (0,-3)  -- (-0.8,-2) node[left]{$1$};
  \node at (0,-4.8){$\kappa=1$};
  \node  at (0,-5.6){$(1,0,0,0)$};
\end{tikzpicture}
\hspace{1mm}
\begin{tikzpicture}[scale=0.6]
  \def\rad{1pt}
  \draw[fill] (0,-3) circle [radius=\rad];
  \draw[fill] (0,-2) circle [radius=\rad];
  \draw[fill] (0,-1) circle [radius=\rad];
  \draw[fill] (0,0) circle [radius=\rad];
  \draw[fill] (0,1) circle [radius=\rad];
  \draw (0,-3) node[below]{$0$} --
        (0,-2) node[left]{$2$} --
        (0,-1) node[left]{$4$} --
        (0,0) node[left]{$3$} --
        (0,1) node[left]{$1$};
  \node at (0,-4.8){$\kappa=2$};
  \node  at (0,-5.6){$(0,0,0,0)$};
\end{tikzpicture}
\hspace{1mm}
\begin{tikzpicture}[scale=0.3]
  \def\rad{1pt}
\node[ball,above,label=above:$4$] (v4) at (0,5) {};
\node[ball,label=right:$3$] (v3) at (2,3) {};
\node[ball,label=left:$2$] (v2) at (-2,3) {};
\node[ball,label=right:$1$] (v1) at (2,0) {};
\node[ball,label=left:$0$] (v0) at (-2,0) {};
\draw (v0)--(v1)--(v3)--(v2)--(v4)--(v3);
\draw (v0)--(v2);
\draw (0,-1.2) node {$G$};
\draw (0,-7.0) node {};
\end{tikzpicture}
\caption{The~$11$ superstable sandpiles on the house graph,~$G$, with
  their~$\kappa$-inversion numbers and corresponding spanning trees
  (via the depth-first search burning algorithm).}\label{fig: dfs house graph}
\end{figure}
\medskip

{\bf Exercise.}
Verify the~$\kappa$ inversion numbers in Figure~\ref{fig: dfs house
  graph}.  For instance, the inversion~$(3,2)$ of the spanning tree
  \begin{tikzpicture}[scale=0.5,baseline=-0.4pt]
      \node[mminiball,label={above:{\tiny 0}}] (0) at (0,0) {};
      \node[mminiball,label={above:{\tiny 1}}] (1) at (1,0) {};
      \node[mminiball,label={above:{\tiny 3}}] (3) at (2,0) {};
      \node[mminiball,label={above:{\tiny 2}}] (2) at (3,0) {};
      \node[mminiball,label={above:{\tiny 4}}] (4) at (4,0) {};
      \draw (0)--(1)--(3)--(2)--(4);
    \end{tikzpicture}
is not a~$\kappa$-inversion since the parent of~$3$ in the tree is~$1$,
and~$\left\{ 1,2 \right\}$ is not an edge of~$G$.  Hence, the inversion number
of~$T$ is~$1$, but~$\kappa(T)=0$.
\medskip

We can now state our main theorem relating the depth-first
search bijection to~$\kappa$-inversions:
\medskip

{\bf Theorem}\label{thm: dfs}  (Chiao-Yu Yang, Kuai Yu, P., 2017) The depth-first search
  algorithm, Algorithm~\ref{alg: dfs}, is a bijection between superstables and
  spanning trees of~$G$.  If~$T$ is the spanning tree corresponding to a
  superstable~$c$, then
  \[
    \kappa(T)=g-\deg(c).
  \]
\medskip

{\bf Exercise.}
  \begin{enumerate}
    \item Pick any superstable on the house graph~$G$ of Figure~\ref{fig: dfs
      house graph}.  Use the depth-first search algorithm to find its
      corresponding tree, and verify that the formula in Theorem~\ref{thm: dfs}
      holds.
    %\item Let~$W$ be the following graph with spanning tree~$T$ in blue:
    \item Let~$W$ be the following graph with spanning tree~$T$ in dashes:
      \begin{center}
	\begin{tikzpicture}[scale=0.5]
	  \node[ball, label={below right:$0$}] (0) at (0,0) {};
	  \node[ball, label={right:$1$}] (1) at (2,0) {};
	  \node[ball, label={above:$2$}] (2) at (0,2) {};
	  \node[ball, label={left:$3$}] (3) at (-2,0) {};
	  \node[ball, label={below:$4$}] (4) at (0,-2) {};
	  \draw (0)--(1);
	  \draw (0)--(2);
%--color change--
%	  \draw[ultra thick, blue] (0)--(3);
%	  \draw[ultra thick, blue](0)--(4);
%	  \draw[ultra thick, blue] (1)--(2);
%	  \draw[ultra thick, blue] (2)--(3);
	  \draw[ultra thick, densely dotted, gray] (0)--(3);
	  \draw[ultra thick, densely dotted, gray](0)--(4);
	  \draw[ultra thick, densely dotted, gray] (1)--(2);
	  \draw[ultra thick, densely dotted, gray] (2)--(3);
	  \draw (3)--(4);
	  \draw (1)--(4);
	\end{tikzpicture}
      \end{center}
      Let vertex~$0$ be the root/sink.  Find the superstable~$c$ that is in
      bijection with~$T$ via the depth-first search algorithm, and verify the
      formula in Theorem~\ref{thm: dfs} holds in this case.
  \end{enumerate}
\end{document}
