Finding Hamiltonian and Longest (s, t)-paths of C-shaped Supergrid Graphs in Linear Time

A supergrid graph is a finite vertex-induced subgraph of the infinite graph whose vertex set consists of all points of the plane with integer coordinates and in which two vertices are adjacent if the difference of their x or y coordinates is not larger than 1. The Hamiltonian path (cycle) problem is to determine whether a graph contains a simple path (cycle) in which each vertex of the graph appears exactly once. This problem is NP-complete for general graphs and it is also NP-complete for general supergrid graphs. Despite the many applications of the problem, it is still open for many classes, including solid supergrid graphs and supergrid graphs with some holes. A graph is called Hamiltonian connected if it contains a Hamiltonian path between any two distinct vertices. In this paper, first we will study the Hamiltonian cycle property of C-shaped supergrid graphs, which are a special case of rectangular supergrid graphs with a rectangular hole. Next, we will show that C-shaped supergrid graphs are Hamiltonian connected except few conditions. Finally, we will compute a longest path between two distinct vertices in these graphs. The Hamiltonian connectivity of C-shaped supergrid graphs can be applied to compute the optimal stitching trace of computer embroidery machines, and construct the minimum printing trace of 3D printers with a C-like component being printed.


Introduction
A Hamiltonian path (cycle) in a graph is a simple path (cycle) in which each vertex of the graph appears exactly once.The Hamiltonian path (cycle) problem involves deciding whether or not a graph contains a Hamiltonian path (cycle).A graph is called Hamiltonian if it contains a Hamiltonian cycle.A graph G is said to be Hamiltonian connected if for each pair of distinct vertices u and v of G, there is a Hamiltonian path from u to v in G.The Hamiltonian path and cycle problems have numerous applications in different areas, including establishing transport routes, production launching, the on-line optimization of flexible manufacturing systems [1], computing the perceptual boundaries of dot patterns [48], pattern recognition [2,50,53], DNA physical mapping [15], fault-tolerant routing for 3D network-on-chip architectures [10], and so on.It is well known that the Hamiltonian path and cycle problems are NP-complete for general graphs [12,30].The same holds true for bipartite graphs [42], split graphs [13], circle graphs [9], undirected path graphs [3], grid graphs [29], triangular grid graphs [14], supergrid graphs [22], etc.
The longest path problem, i.e. the problem of finding a simple path with the maximum number of vertices, is one of the most important problems in graph theory.The Hamiltonian path problem is clearly a special case of the longest path problem.Despite the many applications of the problem, it is still open for some classes of graphs, including solid supergrid graphs and supergrid graphs with some holes [23,24].There are few classes of graphs in which the longest path problem is polynomial solvable [5,28,34,47,54].In the area of approximation algorithms, it has been shown that the problem is not in APX, i.e. there is no polynomial-time constant factor approximation algorithm for the problem unless P=NP [16].Also,it has been shown that finding a path of length n − n ε is not possible in polynomial time unless P=NP [32].That is, the longest path problem is a very difficult graph problem.In this paper, we focus on supergrid graphs.We will give the necessary and sufficient conditions for the Hamiltonian and Hamiltonian connected of C-shaped supergrid graphs.We also present a linear-time algorithm for finding a longest path between any two distinct vertices in a C-shaped supergrid graph.
The two-dimensional integer grid graph G ∞ is an infinite graph whose vertex set consists of all points of the Euclidean plane with integer coordinates and in which two vertices are adjacent if the (Euclidean) distance between them is equal to 1.The two-dimensional triangular grid graph T ∞ is an infinite graph obtained from G ∞ by adding all edges on the lines traced from up-left to down-right.A grid graph is a finite vertex-induced subgraph of G ∞ (see Fig. 1(a)).A triangular grid graph is a finite vertex-induced subgraph of T ∞ (see Fig. 1(b)).Hung et al. [22] have introduced a new class of graphs, namely supergrid graphs.The two-dimensional supergrid graph S ∞ is an infinite graph obtained from T ∞ by adding all edges on the lines traced from up-right to down-left.A supergrid graph is a finite vertex-induced subgraph of S ∞ (see Fig. 1(c)).A solid supergrid graph is a supergrid graph without holes.A rectangular supergrid graph is a supergrid graph bounded by a axis-parallel rectangle (see 2(a)).A L-shaped or C-shaped supergrid graph is a supergrid graph obtained from a rectangular supergrid graph by removing a rectangular supergrid graph from it to make a L-like or C-like shape (see 2(b) and 2(c)).The Hamiltonian connectivity and longest (s, t)-path of shaped supergrid graphs can be applied in computing the optimal stitching trace of computer embroidery machines [22,24,26].
Previous related works are summarized as follows.Recently, Hamiltonian path (cycle) and Hamiltonian connected

Terminologies and background results
In this section, we will introduce some terminologies and symbols.Some observations and previously established results for the Hamiltonicity and Hamiltonian connectivity of rectangular and L-shaped supergrid graphs are also presented.In addition, we also prove some Hamiltonian connected property of R(m, 3), which is a special rectangular supergrid graph, that will be used in proving our result.For graph-theoretic terminology not defined in this paper, the reader is referred to [4].
The two-dimensional integer grid graph G ∞ is an infinite graph whose vertex set consists of all points of the Euclidean plane with integer coordinates and in which two vertices are adjacent if the (Euclidean) distance between them is equal to 1.A grid graph is a finite vertex-induced subgraph of G ∞ .For a node v in the plane with integer coordinates, let v x and v y represent the x and y coordinates of node v, respectively, denoted by v = (v x , v y ).If v is a vertex in a grid graph, then its possible adjacent vertices include (v x , v y − 1), (v x − 1, v y ), (v x + 1, v y ), and (v x , v y + 1) (see Fig. 1(a)).The two-dimensional triangular grid graph T ∞ is an infinite graph obtained from G ∞ by adding all edges on the lines traced from up-left to down-right.A triangular grid graph is a finite vertex-induced subgraph of T ∞ .If v is a vertex in a triangular grid graph, then its possible neighboring vertices include (v x , v y − 1), (v x − 1, v y ), (v x + 1, v y ), (v x , v y + 1), (v x − 1, v y − 1), and (v x + 1, v y + 1) (see Fig. 1(b)).Thus, triangular grid graphs contain grid graphs as subgraphs.The triangular grid graphs defined above are isomorphic to the original triangular grid graphs in [14] but these graphs are different when considered as geometric graphs.
The two-dimensional supergrid graph S ∞ is the infinite graph whose vertex set consists of all points of the plane with integer coordinates and in which two vertices are adjacent if the difference of their x or y coordinates is not larger than 1.A supergrid graph is a finite vertex-induced subgraph of S ∞ .The possible adjacent vertices of a vertex  (v x + 1, v y + 1), (v x + 1, v y − 1), and (v x − 1, v y + 1) (see Fig. 1(c)).Thus, supergrid graphs contain grid graphs and triangular grid graphs as subgraphs.Notice that grid and triangular grid graphs are not subclasses of supergrid graphs, and the converse is also true: these classes of graphs have common elements (points) but in general they are distinct since the edge sets of these graphs are different.It is clear that, all grid graphs are bipartite [29] but triangular grid graphs and supergrid graphs are not bipartite.For a vertex v = (v x , v y ) in a supergrid graph, we color vertex v to be white if v x + v y ≡ 0 (mod 2); otherwise, v is colored to be black.Then there are eight possible neighbors of vertex v including four white vertices and four black vertices.A rectangular supergrid graph, denoted by R(m, n), is a supergrid graph whose vertex set is That is, R(m, n) contains m columns and n rows of vertices in S ∞ .The size of R(m, n) is defined to be mn, and R(m, n) is called n-rectangle.R(m, n) is called even-sized if mn is even, and it is called odd-sized otherwise.Let v = (v x , v y ) be a vertex in R(m, n).The vertex v is called the upper-left (resp., upper-right, down-left, down-right ) corner of R(m, n) if for any vertex w = (w x , w y ) ∈ R(m, n), w x v x and w y v y (resp., w x v x and w y v y , w x v x and w y v y , w x v x and w y v y ).The edge (u, v) is said to be horizontal (resp., vertical ) if u y = v y (resp., u x = v x ), and is called crossed if it is neither a horizontal nor a vertical edge.There are four boundaries in a rectangular supergrid graph R(m, n) with m, n 2. The edge in the boundary of R(m, n) is called boundary edge.A path is called boundary of R(m, n) if it visits all vertices and edges of the same boundary in R(m, n) and its length equals to the number of vertices in the visited boundary.For example, Fig. 3 shows a rectangular supergrid graph R(10, 8) which is called 8-rectangle and contains 2 × (9 + 7) = 32 boundary edges.Fig. 3 also indicates the types of edges and corners.In the figures we will assume that (1, 1) are coordinates of the upper-left corner in a rectangular supergrid graph R(m, n), except we explicitly change this assumption.
A L-shaped supergrid graph, denoted by L(m, n; k, l), is a supergrid graph obtained from a rectangular supergrid graph R(m, n) by removing its subgraph R(k, l) from the upper-right corner, where m, n > 1 and k, l Let G = (V, E) be a supergrid graph with vertex set V (G) and edge set E(G).Let S be a subset of vertices in   In proving our results, we need to partition a rectangular or C-shaped supergrid graph into κ disjoint parts, where κ 2. The partition is defined as follows.
Let R(m, n) be a rectangular supergrid graph with m n 2, C be a cycle of R(m, n), and let H be a boundary of R(m, n), where H is a subgraph of R(m, n).The restriction of C to H is denoted by The following lemma states the result in [22] concerning the Hamiltonicity of rectangular supergrid graphs.Lemma 2.1.(See [22]) Let R(m, n) be a rectangular supergrid graph with m n 2.Then, the following statements hold true: (1) if n = 3, then R(m, 3) contains a canonical Hamiltonian cycle; (2) if n = 2 or n 4, then R(m, n) contains four canonical Hamiltonian cycles with concave faces being on different boundaries.
Fig. 5 shows canonical Hamiltonian cycles for even-sized and odd-sized rectangular supergrid graphs found in Lemma 2.1.Each Hamiltonian cycle found by this lemma contains all the boundary edges on any three sides of the rectangular supergrid graph.This shows that for any rectangular supergrid graph R(m, n) with m n 4, we can always construct four canonical Hamiltonian cycles such that their concave faces are placed on different boundaries.For instance, the four distinct canonical Hamiltonian cycles of R (7,5) are shown in Fig. 5(b)-(e), where the concave faces of these four canonical Hamiltonian cycles are located on different boundaries.Let (G, s, t) denote the supergrid graph G with two specified distinct vertices s and t.Without loss of generality, we will assume that s x t x in the rest of the paper.We denote a Hamiltonian path between s and t in G by HP (G, s, t).We say that HP (G, s, t) does exist if there is a Hamiltonian (s, t)-path in G. From Lemma 2.1, we know that HP (R(m, n), s, t) does exist if m, n 2 and (s, t) is an edge in the constructed Hamiltonian cycle of R(m, n).
For an example, in Fig. 6(b) {s, t} is a vertex cut, and in Fig. 6(a) t is a cut vertex.
In [24], the authors showed that HP (R(m, n), s, t) does not exist if the following condition hold: (F1) s or t is a cut vertex, or {s, t} is a vertex cut (see Fig. 6(a) and Fig. 6(b)).
Let G be any supergrid graphs.The following lemma showing that HP (G, s, t) does not exist if (G, s, t) satisfies condition (F1) can be verified by the arguments in [36].
Lemma 2.2.(See [36]) Let G be a supergrid graph with two vertices s and t.If (G, s, t) satisfies condition (F1), then HP (G, s, t) does not exist.
The Hamiltonian (s, t)-path P of R(m, n) constructed in [24] satisfies that P contains at least one boundary edge of each boundary, and is called canonical.Lemma 2.3.(See [24]) Let R(m, n) be a rectangular supergrid graph with m, n 1, and let s and t be its two distinct vertices.If (R(m, n), s, t) does not satisfy condition (F1), then there exists a canonical Hamiltonian (s, t)-path of R(m, n), i.e., HP (R(m, n), s, t) does exist.
The above result is presented as follows.
Lemma 2.4.(See [41]) Let R(m, n) be a rectangular supergrid graph with m 3 and n 2, s and t be its two distinct vertices, and let w = (1, 1) and z = (2, 1).If (R(m, n), s, t) does not satisfy condition (F1), then there exists a canonical Hamiltonian We then give some observations on the relations among cycle, path, and vertex.These propositions will be used in proving our results and are given in [22,23,24].Proposition 2.5.(See [22,23,24]) Let C 1 and C 2 be two vertex-disjoint cycles of a graph G, let C 1 and P 1 be a cycle and a path, respectively, of G with V (C 1 ) ∩ V (P 1 ) = ∅, and let x be a vertex in G − V (C 1 ) or G − V (P 1 ).Then, the following statements hold true: (1) If there exist two edges e 1 ∈ C 1 and e 2 ∈ C 2 such that e 1 ≈ e 2 , then C 1 and C 2 can be combined into a cycle of G (see Fig. 7(a)).
(2) If there exist two edges e 1 ∈ C 1 and e 2 ∈ P 1 such that e 1 ≈ e 2 , then C 1 and P 1 can be combined into a path of G (see Fig. 7(b)).
Lemma 2.6.(See [24]) Let R(m, 3) be a 3-rectangle with m 3, and let s and t be its two distinct vertices.Then, R(m, 3) contains a canonical Hamiltonian (s, t)-path P which contains at least one boundary edge of each boundary in R(m, 3).By using the above lemma, we will prove the following lemma.
Proof .We will prove this lemma by induction on m.
R contains a Hamiltonian (s, t)-path P such that it contains an edge ẽ = (u, v) locating to face R(k + 1, 3) − R.Then, start( P ) ∼ u and end( P ) ∼ v.By Statement (4) of Proposition 2.5, P and P can be combined into a Hamiltonian (s, t)-path of R(k + 1, 3).The construction of such a Hamiltonian path is depicted in Fig. 8(p).Thus, the lemma holds when m = k + 1.By induction, the lemma holds true.
In addition to condition (F1) (as depicted in Fig. 9(a) and 9(b)), in [41], we showed that HP (L(m, n; k, l), s, t) does not exist whenever one of the following conditions is satisfied.
Theorem 2.9.(See [27]) Let L(m, n; k, l) be a L-shaped supergrid graph.Then, L(m, n; k, l) contains a Hamiltonian cycle if it does not satisfy condition (F5), where condition (F5) is defined as follows: (F5) there exists a vertex w in L(m, n; k, l) such that deg(w) = 1.
In the following, we use L(G, s, t) to denote the length of longest paths between s and t and Û (G, s, t) to indicate the upper bound on the length of longest paths between s and t, where G is a rectangular, L-shaped, or C-shaped supergrid graph.By the length of a path we mean the number of vertices of the path.Let G be a rectangular supergrid graph R(m, n) or L-shaped supergrid graphs L(m, n; k, l).In [24,41], the authors proved the following upper bounds on the length of longest paths in G: ) and (C0) holds, where (C0), (FC1), (FC2), (FC3), (FC4), (FC5), (FC6a), (FC6b), (FC6c), (FC6d) are defined as follows: (C0) (L(m, n; k, l), s, t) does not satisfy any of conditions (F1), (F3), and (F4).
and [(s y , t y > l and {s, t} is not a vertex cut), (s y l and t y > l), or (t y l and s y > l)].Here, and 2 s x = t x m − 1).Here, G ′ = L(m, n − l + 1; k, 1).
Theorem 2.10.[41] Given a rectangular supergrid graph R(m, n) with mn 2 or L-shaped supergrid graph L(m, n; k, l), and two distinct vertices s and t in R(m, n) or L(m, n; k, l), a longest (s, t)-path can be found in O(mn)-linear time.
3 The necessary and sufficient conditions for the Hamiltonian and Hamiltonian connected of C-shaped supergrid graphs In this section, we will give necessary and sufficient conditions for C-shaped supergrid graphs to have a Hamiltonian cycle and Hamiltonian (s, t)-path.10(a).Assume that v ∈ V (R 2 ) and u ∈ V (R 3 ).By Lemma 2.1, R 1 contains a canonical Hamiltonian cycle HC 1 (see Fig. 10(b)).We can place one flat face of HC 1 to face R 2 and R 3 .Thus, there exists an edge (w, z) ∈ HC 1 such that v ∼ w and v ∼ z.By Statement (3) of Proposition 2.5, v and HC 1 can be combined into a cycle HC 2 .By the same argument, u can be merged into the cycle HC 2 to form a Hamiltonian cycle of C(m, n; k, l; c, d), as shown in Fig. 10(c).
Case 2: n > 3. Since n > 3 and c = d = 1, it follows that l > 1.We make a horizontal separation on C(m, n; k, l; c, d) to obtain two disjoint supergrid subgraphs R 1 = L(m, n − n 2 ; k, l 1 ) and R 2 = L(n 2 , m; l 2 , k), where and l 2 = l − l 1 (see Fig. 16(a)-c)).Since n 2 = c + l − 1 and d = 1, clearly n − n 2 = 2. Also since n − n 2 = 2 and n > 3, it follows that n 2 2. Depending on the positions of s and t, there are the following two subcases:   Clearly if this case holds, then (C(m, n; k, l; c, d), s, t) satisfies condition (F7), a contradiction.Therefore, (R 2 , s, t) does not satisfy conditions (F1), (F3), and (F4).Since (R 2 , s, t) does not satisfy conditions (F1), (F3), and (F4).By Theorem 2.8, R 2 contains a Hamiltonian (s, t)-path P 2 in which one edge e 2 is placed to face R 1 .By Theorem 2.9, R 1 contains a Hamiltonian cycle HC 1 such that its one flat face is placed to face R 2 .Then, there exist two edges e 1 ∈ HC 1 and e 2 ∈ P 2 such that e 1 ≈ e 2 (see Fig. 16(d)).By Statement (2) of Proposition 2.5, P 2 and HC 1 can be combined into a Hamiltonian (s, t)-path of C(m, n; k, l; c, d).The construction of a such Hamiltonian path is depicted in Fig. 16(e).
It contradicts that p x = q x = 1 when s x = 1 and t x = 1.
(ii) k > 1 and a < s x , t x < m.If this case holds, then (C(m, n; k, l; c, d), s, t) satisfies condition (F1), a contradiction.
Condition (F3) holds, if k > 1 and s x , t x a.If this case holds, then (C(m, n; k, l; c, d), s, t) satisfies condition (F3), a contradiction.Condition (F4) holds, if a = 2 and [(n 2 > 2 and s y , p y 2) or (n − n 2 > 2 and q y , t y n − 1)].A simple check shows that these cases do not occur.Therefore, (R 2 , s, p) and (R 1 , q, t) do not satisfy conditions (F1), (F3), and (F4).A Hamiltonian (s, t)-path of C(m, n; k, l; c, d) can be constructed by similar arguments in proving Lemma 3.3.Notice that, here, R 1 and R 2 are L-shaped supergrid graphs.).In this subcase, {s, t} is not a vertex cut of R 1 .Then, (R 1 , s, t) does not satisfy condition (F1).By Lemma 2.3, R 1 contains a canonical Hamiltonian (s, t)-path P 1 .Using the algorithm of [24], we can construct a Hamiltonian (s, t)-path P 1 of R 1 in which one edge e 1 is placed to face R 2 .By Theorem 2.9, R 2 contains a Hamiltonian cycle HC 2 .Using the algorithm of [41], we can construct HC 2 such that its one flat face is placed to face R 1 .Then, there exist two edges e 1 ∈ P 1 and e 2 ∈ HC 2 such that e 1 ≈ e 2 (see Fig. 18(d)).By Statement (2) of Proposition 2.5, P 1 and HC 2 can be combined into a Hamiltonian (s, t)-path of C(m, n; k, l; c, d).The construction of a such Hamiltonian path is depicted in Fig. 18(e).
Case 1.2: n − n 2 = 2 and 1 < s x = t x < m.In this subcase, {s, t} is a vertex cut of R 1 .Notice that, here, s x , t x a.If s x , t x > a and k > 1, then (C(m, n; k, l; c, d), s, t) satisfies condition (F1).Without loss of generality, assume that s y < t y .We make a vertical and horizontal separations on R 1 to obtain two disjoint supergrid subgraphs R 11 = L(s x , n − n 2 ; 1, 1) and , and w, z ∈ V (R 2 ) such that p ∼ z, q ∼ w, q = (1, n 2 + 1), w = (1, n 2 ), p = (s x + 1, n 2 + 1), and z = (s x , n 2 ) (see Fig. 19  Case 3: (s ∈ R 1 and t ∈ R 2 ) or (s ∈ R 2 and t ∈ R 1 ).A Hamiltonian (s, t)-path of (C(m, n; k, l; c, d) can be constructed by similar arguments in proving Case 2.2 of Lemma 3.4.Notice that, in this case, R 1 is a rectangular supergrid graphs.
4 The longest (s, t)-paths in C-shaped supergrid graphs From Theorem 3.6, it follows that if (C(m, n; k, l; c, d), s, t) satisfies one of the conditions (F1), (F3), (F7), (F8), and (F9), then (C(m, n; k, l; c, d), s, t) contains no Hamiltonian (s, t)-path.So in this section, first for these cases we give upper bounds on the lengths of longest paths between s and t.Then, we show that these upper bounds is equal to the length of longest paths between s and t.Notice that the isomorphic cases are omitted.The following lemmas give these bounds.
We first consider the case of a = 1.In this case, (C(m, n; k, l; c, d), s, t) may satisfy condition (F1), (F3), or (F9).We compute the upper bound of the longest (s, t)-path in this case as the following lemma.Proof .The proof is straightforward, see Fig. 21.
Next, we consider the case of a 2. In this case, (C(m, n; k, l; c, d), s, t) may satisfy condition (F1), (F3), (F7), or (F8).Depending on the sizes of c and d, we consider the subcases of (1) c 2 and d 2, and (2) c = 1 or d = 1.Consider that c 2 and d 2.Then, (C(m, n; k, l; c, d), s, t) does not satisfy conditions (F3), (F7), and (F8).Thus, (C(m, n; k, l; c, d), s, t) may satisfy condition (F1) only.We can see that s or t is not a cut vertex when a, c, d 2. Thus, {s, t} is a vertex cut when (C(m, n; k, l; c, d), s, t) satisfies condition (F1).We can see from the structure of C(m, n; k, l; c, d) that a, c, or d is equals to 2 if {s, t} is a vertex cut.The following lemma shows the upper bound of the longest (s, t)-path under that a, c, d 2 and (C(m, n; k, l; c, d), s, t) satisfies condition (F1).(FC10) If k 2, a + 1 s x , t x a + k − 1(= m − 1), and [(c = 2 and s y , t y c) or (d = 2, and s y , t y c + l)], without loss of generality assume that d = 2 and s y , t y c + l, then the length of any path between s and t cannot exceed Proof .Consider Fig. 22(a)-(b).Removing s and t clearly disconnects C(m, n; k, l; c, d) into two components G 1 and G 2 .Thus, a simple path between s and t can only go through one of these components.Therefore, its length cannot exceed the size of the largest component.Notice that, for (FC10), the length of any path between s and t is equal to max{ L(G 1 , s, t) + |G 2 |, 2 × (m − s x + 1)} (see Fig. 22(c)-(d)).Since a, c > 1, it is obvious that the length of any path between s and t cannot exceed L(G 1 , s, t) In the following, we will consider that a 2, and (c = 1 or d = 1).Without loss of generality, assume that c = 1.We first make a horizontal and vertical separations on C(m, n; k, l; c, d) to obtain two disjoint subgraphs G 1 = L(m, n; k, l + c) and G 2 = R(m − a, c), as depicted in Fig. 23(a), where a 2, c = 1, and G 2 is a path graph.Depending the locations of s and t, we consider the following cases: Case I: s, t ∈ G 2 .In this case, k > 1, s y = t y = 1, and a + 1 s x , t x m.Then, (C(m, n; k, l; c, d), s, t) may satisfy condition (F1) or (F3), as depicted in Fig. 23(b).
Case II: s ∈ G 1 and t ∈ G 2 .In this case, (C(m, n; k, l; c, d), s, t) may satisfy condition (F1) or (F3), as depicted in Fig. 23(c).Based on the above cases, we compute the upper bounds of longest (s, t)-paths on (C(m, n; k, l; c, d), s, t) under that a 2 and c = 1 as the following lemma.Now, we show how to obtain a longest (s, t)-path for C-shaped supergrid graphs.Notice that if (C(m, n; k, l; c, d), s, t) satisfies (C1), then, by Theorem 3.6, it contains a Hamiltonian (s, t)-path.Proof .We prove this lemma by constructing a (s, t)-path P such that its length equals to Û (C(m, n; k, l; c, d), s, t).Consider the following cases:  , c)), and z ∼ w.Then, G 1 and G 2 are L-shaped and rectangular supergrid graphs, respectively.First, by the algorithms [24] and [41], we can construct a longest (s, z)-path P 2 (resp.P 1 ) in G 2 (resp.G 1 ) and a longest (w, t)-path P 1 (resp.P 2 ) in G 1 (resp.G 2 ), respectively.Then, P = P 2 ⇒ P 1 (resp.P 1 ⇒ P 2 ) forms a longest (s, t)-path of C(m, n; k, l; c, d). ).Since G 11 and G 12 are L-shaped supergrid graphs, by the algorithm of [41] we can construct a longest path between s and t in G 11 and G 12 .Fig. 22(a)-(b) depict such a construction.For conditions (FC14) and (FC15), consider Fig. 27(c)-(f).Then, G 12 may be a rectangle.By the algorithm of [24] we can construct a longest path between s and t in G 12 if it is a rectangle.In addition, G 11 is a C-shaped supergrid graph in (FC15) (see Fig. 27(e).Then, (G 11 , s, t) satisfies condition (FC18).And its longest (s, t)-path can be computed by the algorithm in [41].Its construction is shown in Case 6 and Fig. 27 Then, G 1 is a L-shaped supergrid graph and G 2 is a rectangle.By the algorithm of [41], we can construct a longest path P 1 between s and t in G 1 that contains edge e 1 locating to face G 2 .By Lemma 2.1, G 2 contains canonical Hamiltonian cycle HC 2 such that its one flat face is placed to face G 1 .Thus, by Statement (2) of Proposition 2.5, P 1 and HC 2 can be combined into a longest (s, t)-path of C(m, n; k, l; c, d).
Case 5: Condition (FC11) holds.By Lemma 4.3, Û (C(m, n; k, l; c, d), s, t) = t x − s x + 1. Obviously, the lemma holds for the single possible path between s and t (see Fig. 26

Fig. 1 :
Fig. 1: (a) A grid graph, (b) a triangular grid graph, and (c) a supergrid graph, where circles represent the vertices and solid lines indicate the edges in the graphs.

Fig. 2 :
Fig. 2: (a) A rectangular supergrid graph, (b) a L-shaped supergrid graph, and (c) a C-shaped supergrid graph, where circles represent the vertices and solid lines indicate the edges in the graphs.
1.Then, m−k 1 and n−l 1.A C-shaped supergrid graph C(m, n; k, l; c, d) is a supergrid graph obtained from a rectangular supergrid graph R(m, n) by removing its subgraph R(k, l) from its node coordinated as (m, c + 1) while R(m, n) and R(k, l) have exactly one border side in common, where m 2, n 3, k, l 1, c 1, d = n − l − c 1, and a = m − k 1.The structures of L(m, n; k, l) and C(m, n; k, l; c, d) are explained in Fig. 4(a) and Fig. 4(b), respectively.

Fig. 5 :
Fig. 5: A canonical Hamiltonian cycle containing three flat faces and one concave face for (a) R(8, 6) and (b)-(e) R(7, 5), where solid arrow lines indicate the edges in the cycles and R(7, 5) contains four distinct canonical Hamiltonian cycles in (b)-(e) such that their concave faces are placed on different boundaries.
e. C |H is a boundary path on H, then C |H is called flat face on H.If |C |H | > 1 and C |H contains at least one boundary edge of H, then C |H is called concave face on H.A Hamiltonian cycle of R(m, 3) is called canonical if it contains three flat faces on two shorter boundaries and one longer boundary, and it contains one concave face on the other boundary, where the shorter boundary consists of three vertices.And, a Hamiltonian cycle of R(m, n) with n = 2 or n 4 is said to be canonical if it contains three flat faces on three boundaries, and it contains one concave face on the other boundary.

Fig. 6 :
Fig. 6: Rectangular supergrid graphs in which there is no Hamiltonian (s, t)-path for (a) R(m, 1), and (b) R(m, 2), where solid lines indicate the longest path between s and t.

Fig. 10 :
Fig. 10: (a) A vertical and horizontal separations on C(m, n; k, l; c, d), (b) a Hamiltonian cycle in R 1 , (c) a Hamiltonian cycle in C(m, n; k, l; c, d), and (d) and (e) a horizontal separation on C(m, n; k, l; c, d), where bold solid lines indicate the constructed Hamiltonian cycle and ⊗ represents the destruction of an edge while constructing a Hamiltonian cycle.
(a) and 11(b).By Statement (1) of Proposition 2.5, HC 1 and HC 2 can be combined into a Hamiltonian cycle of C(m, n; k, l; c, d), as shown in Fig. 11(c) and 11(d).

Fig. 13 :
Fig. 13: (a) A horizontal separation on C(m, n; k, l; c, d), (b) Hamiltonian paths P 1 and P 2 in (R 1 , s, p) and (R 2 , q, t), respectively, and (c) a Hamiltonian (s, t)-path in C(m, n; k, l; c, d), where a = 1 and bold lines indicate the constructed Hamiltonian path.

Fig. 17 :
Fig. 17: (a) The pattern for constructing a Hamiltonian (s, t)-path in C(m, n; k, l; c, d) under that c = d = 1, n = 4, 2 s x = t x a − 1, and a = 3, (b)-(c) a vertical and horizontal separations on C(m, n; k, l; c, d) under that c = d = 1, n = 4, 2 s x = t x a − 1, and a > 3, (d) a Hamiltonian (s, t)-path in R 21 and Hamiltonian cycles in R 1 and R 22 for (b), (e) a Hamiltonian (s, t)-path in C(m, n; k, l; c, d) for (b), and (f) a Hamiltonian (s, t)-path in C(m, n; k, l; c, d) for (c).

Lemma 3 . 5 .Fig. 18 :
Fig. 18: (a)-(c) A horizontal separation on C(m, n; k, l; c, d) under that a > 1 and d > 1, (d) a Hamiltonian (s, t)-path in R 1 and a Hamiltonian cycle in R 2 for s, t ∈ R 1 and {s, t} is not a vertex cut of R 1 , and (e) a Hamiltonian (s, t)-path in C(m, n; k, l; c, d) for (d).

Fig. 19 :
Fig. 19: (a)-(c) A vertical and horizontal separations on R 1 under that s, t ∈ R 1 and {s, t} is a vertex cut of R 1 , and (d) a Hamiltonian (s, t)-path in C(m, n; k, l; c, d) for (a).

(
FC8) If (s y c and t y > c) or (t y c and s y > c), without loss of generality assume that s y c, then the length of any path between s and t cannot exceed L(G 2 , s, z) + L(G 1 , w, t), where G 2 = R(m, c), G 1 = L(m, n − c; k, l), and z = (1, c) if s = (1, c); otherwise z = (2, c) (see Fig.21(c)-(d)).

Fig. 21 :
Fig. 21: A longest path between s and t under that a = 1 for (a)-(b) (FC7) holds, and (c)-(d) (FC8) holds, where bold lines indicate the constructed longest (s, t)-path and bold dash lines indicate the separations.
G, and let u and v be two vertices in G.We write G[S] for the subgraph of G induced by S, G − S for the subgraph G[V − S], i.e., the subgraph induced by V − S. In general, we write G − v instead of G − {v}.We say that u is adjacent to v, and u and v are incident to edge (u, v), if (u, v) ∈ E(G).The notation u ∼ v (resp., u ≁ v) means that vertices u and v are adjacent (resp., non-adjacent).A vertex w adjoins edge (u, v) if w ∼ u and w ∼ v.For two edges e 1 = (u 1 , v 1 ) and e 2 = (u 2 , v 2 ), if u 1 ∼ u 2 and v 1 ∼ v 2 , then we say that e 1 and e 2 are parallel, denoted by e 1 ≈ e 2 .For any v ∈ V (G), a neighbor of v is any vertex that is adjacent to v. Let N G (v) be the set of neighbors of v in G, and let N G and all vertices except v 1 , v |P | in it are distinct.The first and last vertices visited by P are denoted by start(P ) and end(P ), respectively.We will use v i ∈ P to denote "P visits vertex v i " and use (v i , v i+1 ) ∈ P to denote "P visits edge (v i , v i+1 )".A path from v 1 to v k is denoted by (v 1 , v k )-path.In addition, we use P to refer to the set of vertices visited by path P if it is understood without ambiguity.A cycle is a path C with |V (C)| 4 and start(C) = end(C).Two paths (or cycles) P 1 and P 2 of graph G are called vertex-disjoint if V (P 1 ) ∩ V (P 2 ) = ∅.If end(P 1 ) ∼ start(P 2 ), then two vertex-disjoint paths P 1 and P 2 can be concatenated into a path, denoted by P 1 ⇒ P 2 .