Keywords

1 Introduction

It is said that the graph theory has its origin in the seven bridges of Königsberg settled by Leonhard Euler [2]. An Eulerian cycle, named after him in modern terminology, is a cycle which uses every edge exactly once, and it is now well-known that a connected undirected graph has an Eulerian cycle if and only if every vertex has an even degree. A Hamiltonian cycle (HC), a similar but completely different notion, is a cycle which visits every vertex exactly once. In contrast to the clear characterization of an Eulerian graph, the question if a given graph has a Hamiltonian cycle is a celebrated NP-complete problem due to Karp [11]. The HC problem is widely interested in computer science or mathematics, and has been approached with several variants or related problems. The traveling salesman problem (TSP) in a graph, which is NP-hard since the HC problem is so, is regarded as a relaxed version of the HC problem, in which the condition of visiting number on each vertex is relaxed to more than once. Another example may be a two-factor (in cubic graphs), which relaxes the condition of the connectivity of an HC, but a two-factor must contain each vertex exactly once (cf. [3, 4, 8, 9]).

It could be a natural idea for the HC problem to modify the condition on the visiting number keeping the connectivity condition. The parity Hamiltonian cycle (PHC) problem, which this paper is involved in, is a variant of the Hamiltonian cycle problem: a PHC is a closed walk (possibly using each edge more than once) which visits every vertex an odd number of times. Note that the PHC problem allows natural variations, directed or undirected, cycle or path, so does the HC. Brigham et al. [5] showed that any connected undirected graph has a parity Hamiltonian path or cycle, by giving an algorithm based on the depth first search. Thirty years later, Nishiyama et al. [14] investigated the PHC problem in undirected graphs, and gave a complete characterization that a connected undirected graph has a PHC if and only if it has an even order or it is non-bipartite. They also showed that any graph satisfying the condition admits a PHC which uses each edge at most four times, by presenting an algorithm to find a PHC using T-joins. On the other hand, the PHC problem becomes NP-complete if each edge is restricted to be used in a PHC at most three times.

This paper investigates a directed version of the PHC problem. We give two characterizations when a directed graph admits a PHC. The characterizations, unlike with the undirected case, are described by linear systems over GF(2). Our characterizations directly imply that the PHC problem in a directed graph is solved in polynomial time. We then give a faster algorithm to recognize if a directed graph has a PHC, which runs in linear time without (explicitly) solving the linear system over GF(2). In the linear time algorithm, T-joins play a key role. We also discuss a problem extended to GF(p), in Sect. 4.

Notice that the condition that an HC visits each vertex \(1 \in \mathbb {R}\) times is replaced by \(1 \in \) GF(2) times in a PHC. Modification of the field is found in group-labeled graphs or nowhere-zero flows [10, 12]. It was recently shown that the extension complexity of the TSP is exponential [6, 7, 17], while it is an interesting question if the PHC problem has an efficient (extended) formulation over GF(2).

2 Definitions and Notations

This section introduces definitions and notations. A directed graph (digraph for short) \(D = (V, A)\) is given by a vertex set V and an arc set A (sometimes we use V(D) and A(D) to clarify the graph which we are focusing on). Let \(\delta ^+(v)\) (resp. \(\delta ^-(v)\)) for \(v \in V\) denote the set of outgoing (resp. incoming) arcs; that is, arcs that leave v (resp. enter v). The sizes \(|\delta ^+(v)|\) and \(|\delta ^-(v)|\) are called the out-degree and the in-degree of v, respectively.

A directed walk is a sequence of vertices and arcs \(v_0a_1 \cdots a_\ell v_\ell \), where \(a_i = (v_{i-1}, v_i) \in A\) for each i \((1 \le i \le \ell )\). A directed walk is closed if \(v_\ell = v_0\). A directed path is a directed walk which contains each vertex at most once except the start vertex \(v_0\) and the end vertex \(v_\ell \). A directed closed path is called a directed cycle. A digraph D is strongly connected if there exists a directed path from u to v for any pair of vertices \(u, v \in V(D)\). For convenience, we often represent a directed closed walk by an integer vector \(\tilde{\varvec{x}} \in \mathbb {Z}_{\ge 0}^A\), in which \(\tilde{x}(a)\) denotes the number of occurrences of arc a in the closed walk.

A cycle basis of D is a set of directed cycles \(\{C_1, C_2, \ldots , C_k\}\) which satisfies conditions: (i) Their incidence vectors \(\varvec{c}_1, \varvec{c}_2, \ldots , \varvec{c}_k \in \{0,1\}^A\) are linearly independent over \(\mathrm{GF}(2)\), and (ii) the incidence vector of every cycle, including those are not directed, can be represented as a linear combination of \(\varvec{c}_1, \varvec{c}_2, \ldots , \varvec{c}_k\). We call each cycle \(C_i\) a fundamental cycle. It is known that the size k of cycle basis is equal to \(|A(D)| - |V(D)| + 1\) [1], and a cycle basis of a digraph can be found in linear time [1, 16].

Parity Hamiltonian Cycle Problem. A parity Hamiltonian cycle (PHC for short) of a digraph D is a directed closed walk in which each vertex appears odd number of times except the starting vertex. In other words, a PHC is a connected closed walk which satisfies a parity condition: \(\sum _{a \in \delta ^+(v)} \tilde{x}(a) \equiv \sum _{a \in \delta ^-(v)} \tilde{x}(a) \equiv 1 \pmod {2}\) for each \(v \in V\). Note that a PHC may use each arc more than once, unlike with HC’s. The parity Hamiltonian cycle problem is a decision problem to decide whether an input graph has a PHC. Note that only strongly connected digraphs have PHC’s, thus we assume that the input digraph is strongly connected in what follows.

3 Main Results

In this section we explain our main result. In Sect. 3.1 we show a characterization of digraphs which have PHC’s, and in Sect. 3.2 we give an algorithm for the PHC problem and one for finding a PHC, and discuss their time complexities.

3.1 Characterization

To state our main result, we define two matrices M and Q. For a digraph D, let \(M^+ = [m_{va}^+] \, and \, M^-= [m_{va}^-] \in \{0,1\}^{|V| \times |A|}\) be matrices respectively defined by

$$\begin{aligned} m_{va}^+ = \left\{ \begin{array}{ll} 1 &{} \text{ if } a \in \delta ^+(v), \\ 0 &{} \text{ otherwise }, \end{array} \right. \text{ and } m_{va}^- = \left\{ \begin{array}{ll} 1 &{} \text{ if } a \in \delta ^-(v), \\ 0 &{} \text{ otherwise }. \end{array} \right. \end{aligned}$$

Thus the parity condition of a PHC is written as \(M^+\tilde{\varvec{x}} \equiv M^-\tilde{\varvec{x}} \equiv \varvec{1}\pmod {2}\). We define a matrix M over \(\{0,1\}^{2|V| \times |A|}\) by

$$\begin{aligned} M = \left[ \begin{array}{l} M^+ \\ M^- \end{array} \right] . \end{aligned}$$

Let \(\{C_1, C_2, \ldots , C_k\}\) \((k = |A| - |V| + 1)\) be a cycle basis of D and let \(\varvec{c}_1, \varvec{c}_1, \ldots , \varvec{c}_k \in \{0,1\}^A\) their incidence vectors. Let \(R = [\varvec{c}_1, \varvec{c}_1, \ldots , \varvec{c}_k]\). We define a matrix \(Q \in \{0,1\}^{|V| \times k}\) by

$$\begin{aligned} Q = M^+R. \end{aligned}$$
(1)

Remark that \(Q = M^-R\) holds, since for each i, the column vector \(\varvec{q}_i \in \{0,1\}^V\) of Q is a vector such that \(q_i(v) = 1\) if and only if \(C_i\) contains \(v \in V\).

Now we are ready to state our main result.

Theorem 1

The following three conditions are equivalent:

 

(a) :

A strongly connected digraph \(D = (V,A)\) has a PHC,

(b) :

\(M\varvec{x} \equiv \varvec{1}\pmod {2}\) has a solution \(\varvec{x} \in \{0,1\}^A\),

(c) :

\(Q\varvec{\beta } \equiv \varvec{1}\pmod {2}\) has a solution \(\varvec{\beta } \in \{0,1\}^k\),

  where \(k=|A|-|V|+1\) and \(\varvec{1}\) denotes the all 1 vector.

Proof

The proofs of (c) \(\Rightarrow \) (a) and (a) \(\Rightarrow \) (b) are easy, while the other way (b) \(\Rightarrow \) (a) and (a) \(\Rightarrow \) (c), as well as (b) \(\Rightarrow \) (c) directly are not trivial. First we show (a) \(\Leftrightarrow \) (b), then we show (a) \(\Leftrightarrow \) (c).

(a) \(\Rightarrow \) (b). Let \(\tilde{\varvec{x}} \in \mathbb {Z}_{\ge 0}^A\) be a vector in which \(\tilde{x}(a)\) denotes the number of uses of \(a \in A\) in a PHC. By the parity condition of PHC, we have \(M^+\tilde{\varvec{x}} \equiv M^-\tilde{\varvec{x}} \equiv \varvec{1}\pmod {2}\). Then let \(\varvec{x} \in \{0,1\}^A\) be defined by \(\varvec{x} \equiv \tilde{\varvec{x}} \pmod {2}\), we have \(M^+\varvec{x} \equiv M^-\varvec{x} \equiv \varvec{1}\pmod {2}\), and thus \(M\varvec{x} \equiv \varvec{1}\pmod {2}\).

(b) \(\Rightarrow \) (a). Suppose that \({\varvec{x}} \in \{0,1\}^A\) is a solution of \(M{\varvec{x}} \equiv {\varvec{1}} \pmod {2}\), then we explain how to construct a PHC. Remark that a graph indicated by \({\varvec{x}}\) satisfies the parity condition of the visiting number on each vertex, but may not satisfy the Eulerian condition, meaning that \(\sum _{a \in \delta ^+(v)} x(a) = \sum _{a \in \delta ^-(v)} x(a)\) may not hold for some vertex v, and connectivity.

First, we construct \({\varvec{x}}' \in \mathbb {Z}_{\ge 0}^{A}\) satisfying both of the parity condition \(M{\varvec{x}}' \equiv \mathbf{{1}} \pmod {2}\) and the Eulerian condition \(\sum _{a \in \delta ^+(v)} x'(a) = \sum _{a \in \delta ^-(v)} x'(a)\) for each \(v \in V\). Let \(\phi (v) = \sum _{a \in \delta ^+(v)} x(a) - \sum _{a \in \delta ^-(v)} x(a)\) for each \(v \in V\), denoting the difference between out-degree and in-degree of v in \(\varvec{x}\). Then \(\varvec{x}\) is Eulerian if and only if \(\phi (v) = 0\) for all v. Notice that \(\sum _{v \in V} \phi (v) = 0\) holds since the total of out-degrees is equal to the total of in-degrees. We also remark that \(\phi (v)\) is even for each \(v \in V\), since \(M{\varvec{x}} \equiv \mathbf{{1}} \pmod {2}\) implies that both of out-degree (\(\sum _{a \in \delta ^+(v)} x(a)\)) and in-degree (\(\sum _{a \in \delta ^-(v)} x(a)\)) are odd. Then we apply the following Procedure 1 to \(\varvec{x}\):

Procedure 1

  1. 1.

    Find \(u, v \in V\) such that \(\phi (u)<0\) and \(\phi (v)>0\).

  2. 2.

    Find a directed path P from u to v (P always exists since D is strongly connected).

  3. 3.

    \(x(a) := x(a) + 2\) for each \(a \in A(P)\).

Procedure 1 preserves the parity condition \(M{\varvec{x}} \equiv \mathbf{{1}} \pmod {2}\), and decreases the value of \(\sum _{v \in V}|\phi (v)|\) (by four). By recursively applying Procedure 1 until \(\sum _{v \in V}|\phi (v)|\) is zero, we obtain a desired closed walk \({\varvec{x}}'\).

If \({\varvec{x}}'\) suggests a connected walk, we obtain a PHC. Suppose that \({\varvec{x}}'\) is not connected. Then we apply the following Procedure 2 to \(\varvec{x}^\prime \):

Procedure 2

  1. 1.

    Find \(u, v \in V\) which are in distinct connected components.

  2. 2.

    Find directed paths P from u to v and \(P^\prime \) from v to u.

  3. 3.

    \(x^\prime (a) := x^\prime (a) + 2\) for each \(a \in A(P) \cup A(P^\prime )\).

Procedure 2 preserves the parity condition \(M{\varvec{x}} \equiv \mathbf{{1}} \pmod {2}\) and the Eulerian condition, and decreases the number of connected components. By recursively applying Procedure 2, we obtain a connected walk, which is in fact a PHC.

(c) \(\Rightarrow \) (a). We construct a PHC from the solution \(\varvec{\beta } \in \{0,1\}^k\). Let

$$\begin{aligned} \alpha _i = \left\{ \begin{array}{ll} 1 &{} \text{ if } \beta _i = 1, \\ 2 &{} \text{ if } \beta _i = 0, \end{array} \right. \end{aligned}$$
(2)

and set \(\varvec{\tilde{x}} = R\varvec{\alpha }\). Notice that \(\tilde{\varvec{x}}\) indicates a closed walk since it is a sum of cycles. We claim that the closed walk indicated by \(\tilde{\varvec{x}}\), say \(\gamma \), is a PHC. The walk \(\gamma \) is connected since \(\gamma \) uses all edges of D at least once, and D is strongly connected. Then, we have

$$\begin{aligned} M^+\tilde{\varvec{x}} = M^+R\varvec{\alpha } = Q\varvec{\alpha } \equiv Q\varvec{\beta } \equiv \varvec{1}\pmod {2}, \end{aligned}$$

where the second last congruence comes from (2) and the last congruence follows from the assumption that \(\varvec{\beta }\) is a solution of \(Q\varvec{\beta } \equiv \varvec{1}\pmod {2}\). Hence, \(\gamma \) satisfies the parity condition, and thus \(\gamma \) is a PHC.

(a) \(\Rightarrow \) (c). To show the necessity we show the following lemma.

Lemma 2

Let \(\gamma \) be any closed walk of D, and let \(\tilde{\varvec{x}} \in \mathbb {Z}_{\ge 0}^A\) be a vector in which \(\tilde{x}(a)\) denotes the number of uses of \(a \in A\) in \(\gamma \). Then \(R\varvec{\beta } \equiv \tilde{\varvec{x}} \pmod {2}\) has a solution \(\varvec{\beta } \in \{0,1\}^k\).

Proof

Since \(\gamma \) is an Eulerian walk in a multi-digraph, meaning that \(\gamma \) consists of simple cycles, \(\tilde{\varvec{x}}\) is represented by

$$\begin{aligned} \tilde{\varvec{x}} = \sum _{j=1}^\ell \alpha _j \varvec{\gamma }_j, \end{aligned}$$
(3)

with appropriate positive integer \(\ell \), where each \(\alpha _j\) is a nonnegative integer and each \(\varvec{\gamma }_j \in \{0,1\}^A\) is the incidence vector of a directed cycle of D. Remark that each \(\varvec{\gamma }_j\) is represented by a linear combination of incidence vectors of fundamental cycles \(\varvec{c}_1, \ldots , \varvec{c}_k\), such that \(\varvec{\gamma }_j \equiv \sum _{i=1}^k \beta _{ij}^\prime \varvec{c}_i \pmod {2}\) for some 0-1 coefficients \(\beta _{ij}^\prime \) for each j. Let \(\beta _i \in \{0,1\}\) be defined by \(\beta _i \equiv \sum _{j=1}^\ell \beta _{ij}^\prime \alpha _j \pmod {2}\), then

$$\begin{aligned} \tilde{\varvec{x}} \equiv \sum _{j=1}^\ell \alpha _j \sum _{i=1}^k \beta _{ij}^\prime \varvec{c}_i \equiv \sum _{i=1}^k \beta _i\varvec{c}_i \pmod {2} \end{aligned}$$

holds. Notice that \(\sum _{i=1}^k \beta _i\varvec{c}_i = R\varvec{\beta }\), then we obtain the claim.    \(\square \)

Suppose that \(\gamma \) is a PHC of D, and that \(\tilde{\varvec{x}} \in \mathbb {Z}_{\ge 0}^A\) is a vector in which \(\tilde{x}(a)\) denotes the number of uses of \(a \in A\) in \(\gamma \). Since a PHC is a closed walk, Lemma 2 implies that there is a vector \(\varvec{\beta } \in \{0,1\}^k\) such that \(\tilde{\varvec{x}} \equiv R\varvec{\beta } \pmod {2}\). Then

$$\begin{aligned} Q\varvec{\beta } = M^+R\varvec{\beta } \equiv M^+\tilde{\varvec{x}} \equiv \varvec{1}\pmod {2}, \end{aligned}$$

where the last congruence comes from the fact that \(\tilde{\varvec{x}}\) indicates a PHC.    \(\square \)

3.2 Recognition in Linear Time

By Theorem 1, we can decide whether or not a given directed graph D has a PHC in polynomial time, by solving a linear system \(M\varvec{x} \equiv \varvec{1}\pmod {2}\) or \(Q\varvec{\beta } \equiv 1 \pmod {2}\), which costs \(\mathcal {O}(|V||A|^2)\) time. This section improves the time complexity for the query to \(\mathcal {O}(|A|)\).

Given an undirected graph \(G = (V,E)\) and \(T \subseteq V\), a T-join of G is an edge set J such that every vertex in T has odd degree and every other vertex has even degree in the subgraph induced by J. There exists a T-join of G if and only if \(|C \cap T|\) is even in each component C of G [15]. Also, a T-join of any undirected graph can be found in linear time [13].

For a digraph \(D = (V,A)\), let BG(D) be an undirected bipartite graph \((V^+, V^-; E)\), where \(V^+\) and \(V^-\) are the copies of V and \(E = \{ u^+v^- \mid (u,v) \in A\}\). One can easily see that the map is bijective. Observe that M of D coincides with the incidence matrix of BG(D), and hence \(|E| = |A|\).

Lemma 3

\(M\varvec{x} \equiv \varvec{1}\pmod {2}\) has a solution if and only if \(BG(D) = (V^+, V^-; E)\) has a \((V^+ \cup V^-)\)-join.

Proof

Let F be any subset of E, and let \(\varvec{x}_F \in \{0,1\}^E\) be its incidence vector. Since M is the incidence matrix of BG(D), the v-th entry of the vector \(M\varvec{x}_F\), \((M\varvec{x}_F)_v\), denotes the degree of v in \(\varvec{x}_F\). Let \(\varvec{x} \in \{0,1\}^E\) be a solution of \(M\varvec{x} \equiv \varvec{1}\pmod {2}\). Then \(\varvec{x}\) indicates a subgraph of BG(D) in which every vertex has odd degree, which is a \((V^+ \cup V^-)\)-join of BG(D). Conversely, if \(\varvec{x}_F \in \{0,1\}^E\) is the incidence vector of a \((V^+ \cup V^-)\)-join F, \(\varvec{x}_F\) satisfies \(M\varvec{x}_F \equiv \varvec{1}\pmod {2}\).    \(\square \)

Since BG(D) and a T-join are computed in linear time, we see the following.

Theorem 4

The PHC problem in digraphs is solved in linear time.    \(\square \)

Finally we remark the time complexity to find a PHC of a given directed graph D. The proof of Lemma 3 implies that we can obtain a solution \({\varvec{x}} \in \{0,1\}^A\) of \(M{\varvec{x}} \equiv \varvec{1}\pmod {2}\) by finding a \((V^+ \cup V^-)\)-join of BG(D). Once we obtain a solution \({\varvec{x}}\), we can construct a PHC according to the proof of Theorem 3.1 for (b) \(\Rightarrow \) (a). The algorithm is summarized in Algorithm 3.1.

It takes \(\mathcal {O}(|A|)\) time in line 1. In line 2, we repeatedly find paths, each path is found in \(\mathcal {O}(|A|)\) time and repeated \(\mathcal {O}(|A|)\) time thus \(\mathcal {O}(|A|^2)\) time in total. In line 3, we repeatedly find pairs of paths, each is done in \(\mathcal {O}(|A|)\) and repeated \(\mathcal {O}(|V|)\) time, thus \(\mathcal {O}(|V||A|)\) time in total. Consequently the time complexity of Algorithm 3.1 is \(\mathcal {O}(|A|^2)\).

4 Extension to \(\mathrm{GF}(p)\)

This section is concerned with the following problem, generalization of the PHC problem: Given a digraph D and an integer p and an integer vector \(\varvec{r} \in \{0,1, \ldots , p-1\}^A\), decide if there exists a closed walk which visits each vertex v r(v) times modulo p. In other words, the problem asks to find a connected closed walk that satisfies the condition \(M^+\tilde{\varvec{x}} \equiv M^-\tilde{\varvec{x}} \equiv \varvec{r} \pmod {p}\), where \(\tilde{\varvec{x}} \in \mathbb {Z}_{\ge 0}^A\) is a vector in which \(\tilde{x}(a)\) denotes the number of uses of arc a in the closed walk. One can see that this is the PHC problem when \(p=2\) and \(\varvec{r} = \varvec{1}\). We give a characterization similar to Theorem 1 (b).

figure a

Theorem 5

A strongly connected digraph D has a connected closed walk which satisfies \(M^+\tilde{\varvec{x}} \equiv M^-\tilde{\varvec{x}} \equiv \varvec{r} \pmod {p}\) if and only if \(M^+\varvec{x} \equiv M^-\varvec{x} \equiv \varvec{r} \pmod {p}\) has a solution \(\varvec{x} \in \{0,\ldots , p-1\}^A\).

Proof

The proof is similar to (a) \(\Leftrightarrow \) (b) of Theorem 1.

Necessity. Let \(\tilde{\varvec{x}} \in \mathbb {Z}_{\ge 0}^A\) be a vector in which \(\tilde{x}(a)\) denotes the number of uses of \(a \in A\) in a connected closed walk which satisfies \(M^+\tilde{\varvec{x}} \equiv M^-\tilde{\varvec{x}} \equiv \varvec{r} \pmod {p}\). Then let \(\varvec{x} \in \{0,\ldots ,p-1\}^A\) be defined by \(\varvec{x} \equiv \tilde{\varvec{x}} \pmod {p}\), we have \(M^+\varvec{x} \equiv M^-\varvec{x} \equiv \varvec{r} \pmod {p}\).

Sufficiency. Suppose that \({\varvec{x}} \in \{0,\ldots ,p-1\}^A\) is a solution of \(M^+{\varvec{x}} \equiv M^-{\varvec{x}} \equiv {\varvec{r}} \pmod {p}\), then we explain how to construct a closed walk which satisfies \(M^+\tilde{\varvec{x}} \equiv M^-\tilde{\varvec{x}} \equiv \varvec{r} \pmod {p}\). Remark that a graph indicated by \({\varvec{x}}\) may not satisfy the Eulerian condition, meaning that \(\sum _{a \in \delta ^+(v)} x(a) = \sum _{a \in \delta ^-(v)} x(a)\) may not hold for some vertex v.

First, we construct \({\varvec{x}}' \in \mathbb {Z}_{\ge 0}^{A}\) satisfying the condition \(M^+{\varvec{x}}^\prime \equiv M^-{\varvec{x}}^\prime \equiv {\varvec{r}} \pmod {p}\) and the Eulerian condition \(\sum _{a \in \delta ^+(v)} x'(a) = \sum _{a \in \delta ^-(v)} x'(a)\) for each \(v \in V\). Let \(\phi (v) = \sum _{a \in \delta ^+(v)} x(a) - \sum _{a \in \delta ^-(v)} x(a)\) for each \(v \in V\), denoting the difference between out-degree and in-degree of v in \(\varvec{x}\). Then \(\varvec{x}\) is Eulerian if and only if \(\phi (v) = 0\) for all v. Notice that \(\sum _{v \in V} \phi (v) = 0\) holds since the total of out-degrees is equal to the total of in-degrees. We also remark that \(\phi (v)\) is a multiple of p for each \(v \in V\), since \(M^+{\varvec{x}} \equiv M^-{\varvec{x}} \equiv {\varvec{r}} \pmod {p}\) implies that both of out-degree (\(\sum _{a \in \delta ^+(v)} x(a)\)) and in-degree (\(\sum _{a \in \delta ^-(v)} x(a)\)) are r(v) modulo p. Then we apply the following Procedure 1’ to \(\varvec{x}\):

Procedure 1’

  1. 1.

    Find \(u, v \in V\) such that \(\phi (u)<0\) and \(\phi (v)>0\).

  2. 2.

    Find a directed path P from u to v (P always exists since D is strongly connected).

  3. 3.

    \(x(a) := x(a) + p\) for each \(a \in A(P)\).

Procedure 1’ preserves the condition \(M^+{\varvec{x}} \equiv M^-{\varvec{x}} \equiv {\varvec{r}} \pmod {p}\), and decreases the value of \(\sum _{v \in V}|\phi (v)|\) (by 2p). By recursively applying Procedure 1’ until \(\sum _{v \in V}|\phi (v)|\) is zero, we obtain a desired closed walk \({\varvec{x}}'\).

If \({\varvec{x}}'\) suggests a connected walk, we obtain a closed walk which satisfies \(M^+\tilde{\varvec{x}} \equiv M^-\tilde{\varvec{x}} \equiv \varvec{r} \pmod {p}\). Suppose that \({\varvec{x}}'\) is not connected. Then we apply the following Procedure 2’ to \(\varvec{x}^\prime \):

Procedure 2’

  1. 1.

    Find \(u, v \in V\) which are in distinct connected components.

  2. 2.

    Find directed paths P from u to v and \(P^\prime \) from v to u.

  3. 3.

    \(x^\prime (a) := x^\prime (a) + p\) for each \(a \in A(P) \cup A(P^\prime )\).

Procedure 2’ preserves the condition \(M^+{\varvec{x}} \equiv M^-{\varvec{x}} \equiv {\varvec{r}} \pmod {p}\) and the Eulerian condition, and decreases the number of connected components. By recursively applying Procedure 2’, we obtain a connected closed walk which satisfies \(M^+\tilde{\varvec{x}} \equiv M^-\tilde{\varvec{x}} \equiv \varvec{r} \pmod {p}\).    \(\square \)

If p is prime or power of a prime, the linear system \(M^+\varvec{x} \equiv M^-\varvec{x} \equiv \varvec{r} \pmod {p}\) is solved over \(\mathrm{GF}(p)\), and we obtain a desired closed walk in polynomial time. Otherwise \(\mathrm{GF}(p)\) is not a field, and we need an extra observation to solve the equation efficiently.

5 Concluding Remarks

This paper gave two characterizations when a directed graph has a PHC. We have also shown that the characterization by M is generalized to problems over GF(p).

The PHC orientation problem is a problem to decide if a given undirected graph has an orientation which has a PHC. Figure 1 shows an example of an undirected graph which has a PHC, but does not admit a PHC orientation. It is open if the PHC orientation problem is solved in polynomial time. Another interesting question is if a PHC in a directed graph has an efficient (extended) formulation. Notice that minimizing the length of a PHC is NP-hard, since a PHC with length n is exactly a Hamiltonian cycle. A further connection between PHC and HC is a future work.

Fig. 1.
figure 1

An undirected graph which has a PHC but does not have a PHC orientation. The arrow indicates a PHC.