Journal of Graph Algorithms and Applications Minimizing the Number of Label Transitions around a Nonseparating Vertex of a Planar Graph

We study the minimum number of label transitions around a given vertex v0 in a planar multigraph G, in which the edges incident with v0 are labelled with integers 1,. .. , l, and the minimum is taken over all embeddings of G in the plane. For a fixed number of labels, a linear-time fixed-parameter tractable algorithm that computes the minimum number of label transitions around v0 is presented. If the number of labels is unconstrained, then the problem of deciding whether the minimum number of label transitions is at most k is NP-complete.


Introduction
Let G be a planar multigraph.Suppose that the edges incident with a vertex v 0 ∈ V (G) are labelled by integers 1, . . ., l.We are interested in finding an embedding of G in the plane such that the number of label transitions around v 0 is minimized.By a label transition we mean two edges that are consecutive in the local rotation around v 0 and whose labels are different.The motivation for this problem comes from investigations of minimum genus embeddings of graphs with small separations.In particular, to compute the genus of a 2-sum of two graphs [12], see also [6,7,11], it is necessary to know if a graph admits a planar embedding with only four label transitions (where l = 2).The problem of minimizing the number of transitions may also be of interest in bioinformatics.Namely, problems arising in genome sequencing and in relation to phylogenetic trees involve notions very close to the minimization of transitions.Our solution in this paper answers a question posed by Cedric Chauve [3] in relation to a generalization of the Consecutive Ones Property of matrices.
By deleting the vertex v 0 from G and putting all edge labels onto vertices incident with the deleted edges, we obtain an equivalent formulation of the same problem.We may assume that the edges incident with the same vertex v = v 0 have different labels because such edges can always be drawn next to each other without increasing the number of label transitions.Both representations are useful and will be treated in this paper.Let H be the graph obtained from G by deleting v 0 .For each v ∈ V (H), let λ(v) be the set of all labels of edges joining v and v 0 in G.If v is not a neighbor of v 0 , then λ(v) = ∅.The pair (H, λ) carries the whole information about G and the labels of edges around v 0 (assuming that the edges incident with the same vertex v = v 0 have different labels).
Let L be a set of labels.The graph H together with the labelling λ : V (H) → 2 L is a labelled graph.Let H be the graph obtained from a labelled graph H by adding a vertex v 0 to H and joining it to each vertex v by |λ(v)| edges and labelling these edges by elements of λ(v).The vertex v 0 is called the center of H.If the graph H is planar (which can be checked in linear time, see [9]), we are back to an instance of the original problem.
Given (H, λ) or H, v 0 , and the labelling of edges incident with v 0 , consider an embedding Π of H in the plane (all embeddings in this paper are into the plane).Define the label sequence Q = Q(Π) of Π to be the cyclic sequence of labels of edges emanating from v 0 in the clockwise order of the local rotation around v 0 in Π.The origin of a label L ∈ Q that came from an edge vv 0 is the vertex v.A label transition in Q is a pair of (cyclically) consecutive labels A, B in Q such that A = B.The number of transitions τ (Q) of Q is the number of label transitions in Q.The number of transitions τ ( H) of H is the minimum τ (Q(Π)) taken over all planar embeddings Π of H.When considering label transitions, the graphs H and H are used interchangeably, i.e., we may write τ (H) instead of τ ( H).
A cutvertex in a graph G is a vertex of G whose removal increases the number of components of G.A vertex is nonseparating if it is not a cutvertex.
The following problem will be of our main interest: Min-Trans.Given a planar multigraph G with edges incident to a fixed vertex v 0 labelled by 1, . . ., l and an integer k, determine if τ (G) ≤ k.
In the following, we show that Min-Trans can be solved in linear time when v 0 is nonseparating and the number of labels l is fixed.
Theorem 1 For every fixed integer l, there is a linear-time algorithm that determines the minimum number of transitions τ (G) of a given planar multigraph G with edges incident to a fixed nonseparating vertex v 0 labelled by at most l different labels.In particular, the Min-Trans problem when v 0 is nonseparating is fixed-parameter tractable for the parameter l.
The proof of Theorem 1 is given in Sections 3 and 4. Let us observe that the time complexity of our algorithm remains near-linear O(n 1+ε ) (for any ε > 0) as long as l = o(log log log n) where n is the size of the input.
If we allow v 0 to be a cutvertex, then the problem changes dramatically.Though the formalism developed in this paper is not sufficient to deal with this general case, we believe that it can also be solved in linear time for every fixed l.
We also show that our algorithmic result is best possible in the sense that Min-Trans becomes NP-complete when l is part of the input.
Theorem 2 Min-Trans is NP-complete if the number of labels l is unconstrained.The problem remains NP-complete even when v 0 is nonseparating and each label occurs precisely twice.
The proof of Theorem 2 is deferred to Section 5.

Outline
The main ideas of our algorithm are described by the following steps.First, we simplify the input graph G so that every 2-connected component of G − v 0 is either an edge or a cycle bounding a face.We call the resulting graph a cactus.
Having obtained the simplified graph, we consider the tree-structure of its blocks using a dynamic programming approach.Herefrom we consider a cactus with a distinguished vertex (root).For each pair A, B of labels, we keep information about the minimum number of transitions ρ[A, B] assuming that the label sequence starts and ends at the root and the sequence is prepended and appended with A and B, respectively.After establishing Lemma 6 that covers concatenations of optimal label sequences, the recursive procedure is rather straightforward, except for the case when the root has big degree.This is the hard part and the details are presented in Section 4.
The main observation is that we only have to distinguish, for each block incident with the root, the l 2 values ρ[A, B] (where l is the fixed number of labels) and that the important information is only how the values differ from ν = min A,B ρ[A, B].The difference ρ[A, B] − ν is either 0, 1, or 2. We can store the complete information about this difference in a variable taking at most 3 l 2 different values.These values are called types.The blocks with the same type need not be distinguished.
In order to determine an optimal sequence of blocks incident with the root, we transform the problem into a problem of finding an optimum closed walk in a multigraph K on l vertices (corresponding to the labels) in which each pair of vertices is joined by 3 l 2 edges (one for each possible type).In this closed walk, the number of edges corresponding to any particular type p must be equal to the number of blocks incident with the root whose type is equal to p.The edge of K corresponding to the type p between vertices A and B is given weight equal to the value of p at A, B. Although the number of closed walks is exponential, we show that one can restrict himself to consider only a constant number of walks in K.The details are given in Section 4.
Let W be an optimal closed walk in K.We consider W as a multiset of edges, the multiplicities corresponding to the number of times each edge appears in W .The walk W can be decomposed into two parts, a closed walk S and an eulerian multiset T of edges, where S has constant size and traverses each edges traversed by W at least once.Moreover, T contains only edges that have weight 0 and for each type p, the number n p of edges in T (counted with appropriate multiplicities of the multiset) that corresponds to p is even.An important property of such a decomposition S, T is that there exists a multiset T of edges of K such that T also satisfies the properties above and uses n p edges of type p.The set T can be constructed in the following way.For each type p, we pick an edge e p of S with weight 0 that corresponds to p.The multiset T consists of the edge e p with multiplicity n p for each type p.It is not hard to check that S and T form a decomposition of a closed walk in K that has the same total weight as the original walk.Therefore, S, T also decomposes an optimal closed walk.There are bounded number of closed walks S to be considered and for each such closed walk, we define T and check if the pair S, T satisfies the required conditions.This yields a constant-time algorithm with linear-time preprocessing that determines the types of the blocks incident with the root.

Bounded Number of Labels
In this section we develop most of the formalism needed to prove Theorem 1.In particular, it is observed that we can restrict our attention to a special class of cactus graphs; also, the basic structure of the algorithm is presented.
Let H and G be labelled graphs with labellings λ and µ, respectively.If every label sequence of (H, λ) is also a label sequence of (G, µ), and vice versa, then H and G are said to be equivalent.
A connected graph G is called a cactus if every block of G is either an edge or a cycle.(A block in a connected graph G is either a cutedge or a maximal 2connected subgraph of G).A labelled cactus G is leaf-labelled if every endblock of G is an edge, every vertex of G has at most one label, and a vertex of G is labelled if and only if it is a leaf.
The following lemma shows that it suffices to prove Theorem 1 for the case when H is a leaf-labelled cactus.To avoid trivialities, we shall assume that there are at least two vertices whose label set λ(v) is non-empty.
Lemma 1 Let H be a connected labelled graph.If H is planar, then there exists a leaf-labelled cactus G which is equivalent to H. Furthermore, G can be constructed in linear time.
Proof: We construct G from H in the following series of steps.First, we move the labels onto leaves.After that we remove unlabelled parts of the graph and finally we remove the insides of cycles.
Construct H from H in the following manner.For each labelled vertex to v and then remove all labels from v. Label each v L with the label L. A planar embedding of H can be transformed to an embedding of H with the same label sequence by contracting the edges vv L , v ∈ V (H), L ∈ λ(v), in H . Conversely, a planar embedding of H can be transformed to an embedding of H with the same label sequence by subdividing the edges incident to the center of H. Hence H and H are equivalent.
Suppose that v is a cutvertex of H and a component B of H − v contains no labels.Since every planar embedding of H − B = H − B can be extended to an embedding of H with the same label sequence by embedding B in one of the faces around v, the labelled graphs H and H − B are equivalent.For each cutvertex v, remove all unlabelled components of H − v from H to obtain H that is equivalent to H .It follows that every endblock of H contains a label.The subgraph H can be easily constructed in linear time by cutting off the appropriate endblocks of H .
Let Π be a planar embedding of H and v 0 the center of H . Let G be the subgraph of H that is formed by the vertices and edges of the facial walk in H − v 0 corresponding to the face in which v 0 was embedded.Note that G contains all labelled vertices of H .We claim that G is equivalent to H . Since G is a subgraph of H , every embedding of H gives an embedding of G with the same label sequence.By construction, every block of G is either an edge or a cycle.Since every endblock of H contains a label, also every endblock of G contains a label.Thus, in every planar embedding of G, every cycle of G is a facial cycle.Hence, an embedding of G can be extended to an embedding of H with the same label sequence by embedding the rest of H into the facial cycles as given in Π .Hence G and H are equivalent.
Since a planar embedding of H can be obtained in linear time (see for example [4]), G can be constructed in linear time.It is not difficult to check that G is a leaf-labelled cactus as required.
In our algorithm, we use a rooted version of graphs.A root r in a leaflabelled cactus H can be any vertex of H.The root is marked by a special label L r ∈ L. We then speak of a rooted leaf-labelled cactus, or simply a cactus (H, r).The restriction on labels in a rooted leaf-labelled cactus is slightly relaxed, every leaf still has precisely one label (possibly L r ) and a non-leaf vertex is labelled only if it is the root.When a label sequence Q of H is cut at the label L r (and L r is deleted), we obtain a linear sequence called a rooted label sequence of H. Let Q(H) denote the set of all rooted label sequences of H. Similarly to the unrooted graphs, two rooted graphs are equivalent if they admit the same rooted label sequences.
There exists a tree-like structure, called a PC-tree (see [13]), that captures all embeddings of a cactus in the plane.PC-trees and their rooted version, PQtrees, are used in testing planarity [1], see also [4].We note that Min-Trans (with v 0 nonseparating) reduces to the problem of minimizing the number of label transitions over all cyclic permutations of the leaves of a PC-tree that are compatible with the PC-tree.
For every embedding Π of H, there is the flipped embedding Π of H where each clockwise rotation in Π is a counter-clockwise rotation in Π .The following lemma formulates this for a rooted label sequence of H.For a linear sequence Q, let Q R denote the sequence obtained by reversing Q.
Lemma 2 Let (H, r) be a rooted leaf-labelled cactus.If Q is a rooted label sequence of H, then the reversed sequence Q R is also a rooted label sequence of H.
The following lemmas establish a recursive construction of rooted label sequences.Let us recall that for a cutvertex v of H, a v-bridge in H is a subgraph of H consisting of a connected component of H − v together with all edges joining this component and v.
Lemma 3 Let (H, r) be a rooted leaf-labelled cactus where r is a leaf.Let u be the neighbor of r.If u is labelled, then H is of order 2 and has a unique rooted label sequence Q = λ(u).Otherwise, (H, r) is equivalent to (H − r, u).
Proof: If u is labelled, then u is a leaf and H contains precisely one label λ(u) and therefore λ(u) is the unique rooted label sequence of H. Otherwise, take an embedding of H − r in the plane.Recall that u as the root of H − r is given a special label L u and thus there is an edge connecting u and the center of H − r.Subdividing this edge gives a planar embedding of H with the same rooted label sequence.Similarly, one can obtain an embedding of H − r from an embedding of H with the same rooted label sequence.
Lemma 4 Let (H, r) be a rooted leaf-labelled cactus such that r is a cutvertex and let B 1 , . . ., B k be the r-bridges in H. Every rooted label sequence of H can be partitioned into k consecutive parts where each of the k parts is a rooted label sequence of one of Proof: Suppose for a contradiction that there is a rooted label sequence Q of H with a cyclic subsequence L 1 L 2 L 3 L 4 (in this order) such that L 1 and L 3 have origins in B 1 and L 2 , L 4 have origins outside B 1 .Let Π be an embedding of H that corresponds to Q and v 1 , . . ., v 4 the origins of L 1 , . . ., L 4 .Let G be the graph obtained from H by deleting the center v 0 and adding an edge uv for every two consecutive edges uv 0 , vv 0 in the local rotation around v 0 .The embedding Π can be extended to a planar embedding Π of G such that the added edges form a facial cycle.Since v 1 and v 3 are in B 1 , there is a path P in B 1 − r joining v 1 and v 3 .Similarly, there is a path Q in H − (B 1 − r) joining v 2 and v 4 .Since P and Q are disjoint and both are embedded inside C, their endvertices cannot interlace on C.This contradiction proves the claim and implies that all labels in each B i appear consecutively in every rooted label sequence of H.This proves the first part of the lemma.
The second part is an easy consequence of the fact that arbitrary embeddings of B i (1 ≤ i ≤ k) can be combined into an embedding of H so that the cyclic order of r-bridges around r is Lemma 5 Let (H, r) be a rooted leaf-labelled cactus with r in a cycle C of length k.If D r (C) is empty, then every rooted label sequence Q of H can be partitioned into k − 1 (possibly empty) consecutive parts P v , v ∈ V (C) \ {r}, where P v is a rooted label sequence of (D v (C), v) and P v appear in Q in one of the two orders corresponding to the two orientations of C.
Proof: Let Q be a rooted label sequence of H such that the conclusion of the lemma is not true.If labels contained in one of the subgraphs D v (C) do not form a consecutive subsequence of Q, we obtain a contradiction as in the proof of Lemma 4. Suppose now that Q contains a cyclic subsequence L 1 L 3 L 2 L 4 of labels (in this order) such that the origins u 1 , . . ., u 4 of L 1 , . . ., L 4 are in D v1 (C), . . ., D v4 (C) and v 1 , v 2 , v 3 , v 4 appear on C in this order.Let Π be an embedding of H that corresponds to Q and let G be the graph obtained from H by deleting the center v 0 and adding an edge uv for every two consecutive edges uv 0 , vv 0 in the local rotation around v 0 .The embedding Π can be easily modified to a planar embedding Π of G.It is easy to check that u 1 , . . ., u 4 , v 1 , v 3 are the branch-vertices of a subdivision of K 3,3 in G, a contradiction with G being planar.
We are interested in rooted label sequences that have the minimum number of transitions.But to combine them later on, it is important to specify the first and the last label in the rooted label sequence.This motivates the following definition.Let Q be a set of (linear) label sequences.We say that a sequence where AQB is the sequence obtained from Q by adding labels A and B at the beginning and at the end of Q, respectively.A rooted label sequence Q of (H, r) is AB-minimal if Q is AB-minimal in Q(H).Minimal sequences are composed of minimal sequences as the following lemma shows.This allows us to restrict our attention to minimal sequences.
Lemma 6 Let Q be the set of all sequences that are concatenations of a sequence in Q 1 and a sequence in Q 2 (in this order).Then for A, B ∈ L, every ABminimal sequence Q in Q is a concatenation of an AC-minimal sequence in Q 1 and a CB-minimal sequence in Q 2 for some label C ∈ L.
Proof: Suppose that the lemma is not true for labels A, B.
again a contradiction with the choice of Q.
Let (H, r) be a rooted leaf-labelled cactus.We can describe "optimal" embeddings of H in the plane by a set of AB-minimal rooted label sequences of H, one for each pair of labels A, B ∈ L. Let ρ H [A, B] be the minimum number of label transitions in an AB-minimal rooted label sequence of H.Note that the values of ρ H differ by at most 2 since adding labels A and B to a sequence increases the number of label transitions by at most 2. Hence we can represent ρ H by the minimum ρ H [A, B] over all labels A, B and by the individual differences from this minimum.Let n H be the minimum number of label transitions in a rooted label sequence of H and let p H It is convenient to view the type as a number between 1 and t := 3 l 2 , whose digits in the ternary system correspond to the particular values p H [A, B] (for some linear ordering of all pairs (A, B) ∈ L × L).Note that the number t of different types is a constant when the number of labels is fixed.We will see in Lemma 8 that rooted cacti of the same type are interchangeable in any ordering around a cutvertex.We call the pair (p H , n H ) the descriptor of H.For simplicity, we also call the function ρ H the descriptor of H since it is easy to compute ρ H from (p H , n H ), and vice versa.
Note that the "unrooted" number of transitions τ (H) can be obtained from the descriptor of H as

JGAA, 16(2) 225-241 (2012) 233
To see this, suppose first that Q is a cyclic label sequence of H (containing L r ) and A is a label next to L r in Q.Let R be the cyclic sequence obtained from Q by replacing L r with two labels A. Then R has the same number of transitions as the cyclic sequence Q − L r .By splitting R between the two new labels A, we obtain a linear sequence ASA, where S is a rooted label sequence of H, with the same number of transitions as in R.This shows that τ (H) For the other inequality, note that from a linear sequence ASA, where S is a rooted label sequence of H, we can obtain a cyclic label sequence of H with smaller or equal number of label transitions by joining the ends of ASA and then deleting the two labels A.
Next, we consider how a descriptor of a rooted leaf-labelled cactus can be computed from descriptors of its subcacti.The first non-trivial case is when the root lies on a cycle.Lemma 7 Let (H, r) be a rooted leaf-labelled cactus such that r is a vertex of degree 2 in a cycle C of length k in H. Then the descriptor of H can be computed from descriptors of Proof: In contrast with rooting at a cutvertex, the order of subgraphs D v (C) around C is fixed.Let us take an embedding of C and let r, v 1 , . . ., v k−1 be the vertices of C in the clockwise order.By Lemma 5, every sequence in ) in this or the reverse order.Let P i be the set of sequences that are concatenation of k − i sequences from Q(D vi (C)), . . ., Q(D v k−1 )(C) in this order.By Lemma 6, every AB-minimal sequence in P i is obtained as a concatenation of an AL-minimal sequence in Q(D vi (C)) and an LB-minimal sequence in P i+1 for some L ∈ L. Let q i [A, B] be the number of transitions in an AB-minimal sequence of P i .Since Note that q 1 stores the number of transitions of all AB-minimal rooted label sequences of H when the order of C is fixed.To allow for flipping of C, we note that an AB-minimal rooted label sequence of H is a BA-minimal rooted sequence of H in the flipped embedding of H. Hence For each 1 ≤ i ≤ k − 1, we compute each of the l 2 values of q i in time O(l).That gives the overall time complexity O(l 3 k).
Computing the descriptor of a leaf-labelled cactus rooted at a cutvertex turns out to be the crux.Let (H, r) be a rooted leaf-labelled cactus where r is a cutvertex of H and let B 1 , . . ., B k be the r-bridges in H. Let b H (i) be the number of r-bridges in H of type i, i = 1, . . ., t.We view b H as an integer vector in Z t with t i=1 b H (i) = k.A non-negative integer vector b ∈ Z t is called a bridge vector and sum(b) = t i=1 b(i) the sum of b.Note that there are at most O(k t+1 ) different non-negative integer vectors b in Z t with the sum at most k.
Each bridge vector b describes a problem to be solved: How to order k, k = sum(b), bridges of types given by b around a vertex so that the number of label transitions on the boundaries between bridges is minimized.We will see that each ordered sequence of types in b gives a sequence of labels with each type being a connection to the next label.Although this sequence of labels is not unique, it is a useful concept that will be heavily used in Section 4. For fixed labels A, B, let R AB (n) be the set of sequences of n + 1 labels (L 0 , . . ., L n ) such that L 0 = A and L n = B. Let P = (p 1 , . . ., p k ) be a sequence containing all types occurring in b (with appropriate multiplicities).For such an ordering of types in b and a sequence be the the minimum m(P, R) taken over all orderings P of b and all sequences R ∈ R AB (k), k = sum(b).This minimum depends only on the types of the bridges, not on the minimum number of label transitions of the bridges.
The fact that computation of m b is a solution to the posed problem and that it gives a way to compute the descriptor of a leaf-labelled cactus rooted at a cutvertex is made precise in the following lemma.
Lemma 8 Let (H, r) be a rooted leaf-labelled cactus and let B 1 , . . ., B k be the r-bridges in H. Then Proof: Let Q be an AB-minimal rooted label sequence of H.By Lemma 4 and repeated application of Lemma 6, the sequence Q is a concatenation of sequences minimal rooted label sequence of (B i , r) for some labels L i such that L 0 = A and L k = B, and (j 1 , . . ., j k ) is a permutation of (1, . . ., k).For i = 1, . . ., k, let p i be the type of B ji .Let R = (L 0 , . . ., L k ) and P = (p 1 , . . ., p k ).Then m(P, R) Conversely, let P = (p 1 , . . ., p k ) be a sequence of k types such that there is a permutation (j 1 , . . ., j k ) of (1, . . ., k) such that the type of B ji is p i .Let R = (L 0 , . . ., L k ) be a sequence of k + 1 labels and let Q i be an L i−1 L i -minimal rooted label sequence in (B ji , r).By Lemma 4, This gives rise to the following dynamic program.Given a non-zero bridge vector b, there are only t possibilities for the type p of the first bridge whose label sequence starts a minimal label sequence of H (the existence of such a bridge follows from Lemma 4).By deleting the type p from b, we obtain a smaller bridge vector b p .The value m bp is computed recursively and then combined with p to obtain m b .However, using this approach would yield a polynomialtime algorithm that is not fixed parameter tractable (since there are Θ(n t ) bridge vectors of sum at most n).In the next section, we sidestep this problem and present a linear-time algorithm for computing m b .
Finally, let us outline an algorithm for Min-Trans that, as we show in the next section, yields Theorem 1.We assume that the input graph has at least three labels to avoid trivialities.

Algorithm 1:
Input: a labelled graph G Output: the minimum number of transitions τ (G) 1 Construct the leaf-labelled cactus H that is equivalent to G (Lemma 1).
2 Root H at an arbitrary unlabelled vertex r.
Function Descriptor(H, r) Input: a rooted leaf-labelled cactus (H, r) Output: the descriptor ρ H of H 1 switch according to the role of r do 2 case r is a leaf and its neighbor u is labelled 3 Note that F has just two vertices r and u. 4 The descriptor ρ H corresponds to the single-label sequence λ(u).18 return ρ H .
Note that throughout Algorithm 1, each vertex of H appears as a root in Descriptor at most twice; once as a cutvertex and once either as a leaf or on a cycle.Therefore, each of the cases can happen at most n times, n = |V (H)|, and the basic recursion runs in linear time.By Lemma 7, the case when the root is in a cycle takes time O(l 3 n) since the sum of lengths of all cycles is bounded by n.If we can compute m b for a bridge vector b in constant time, then Algorithm 1 runs in linear time.This is the goal of the next section.

Dealing with Bridge Vectors
In the previous section we have sketched an algorithm for computing the minimum number of label transitions in a planar multigraph when v 0 is nonseparating.In this section we outline an algorithm for computing m b of a bridge vector b in constant time (Lemma 13), the last ingredient for the proof of Theorem 1.We start by observing that m b is bounded independently of the bridge vector b.Let us recall that t = 3 l 2 and t is the number of types.
for all labels A , B and there are at most t − 1 transitions between different types, We show next that each ordering of b given by an ordering P of types in b and a label sequence R ∈ R A,B (sum(b)) corresponds to a walk in a particular multigraph of constant size.Let K be the complete edge-colored and edgeweighted multigraph on vertex set L where two vertices A, B ∈ L are joined by t edges such that the pth edge is colored by p and has weight p[A, B].Note that there are t loops at every vertex of K.For a walk W in K, the weight w(W ) of W is the sum of weights of edges in W .Let P = (p 1 , . . ., p k ) be an ordering of types in a bridge vector b and R = (L 0 , . . ., L k ) be a sequence of labels.The sequences P , R generate a walk W in K of length k where in the ith step the edge L i−1 L i with color p i is used.The weight of W is m(P, R).The walk W uses b(p) edges of color p.The converse statement also holds: A walk W that uses b(p) edges of color p gives an ordering P of types in b and a label sequence R such that m(P, R) = w(W ).This gives the following lemma.
Lemma 10 Let b be a bridge vector, A, B labels, and w an integer.There is an AB-walk W of weight w in K such that W uses b(p) edges of color p if and only if there is an ordering P of types in b and a label sequence R = (A, . . ., B) such that m(P, R) = w.
In the rest of this section, we will work with multisets, that is, sets where we remember the multiplicity of the elements in the multiset.If an element is not in the multiset, we also say that its multiplicity is 0. In the union A of two multisets A 1 and A 2 , A = A 1 ∪ A 2 , the multiplicity of an element a in A is the sum of the multiplicities of a in A 1 and A 2 .Similarly, we define the difference of two multisets, denoted A 1 − A 2 .A multiset A is a submultiset of a multiset B, A ⊆ B, if, for every a ∈ A, the multiplicity of a in A is at most the multiplicity of a in B.
For a multigraph G and a set (multiset) S of edges in G, the subgraph G(S) induced by S is the graph with edge-set S (the set of edges in S without their multiplicity) and whose vertices are all those vertices of G that are incident with an edge in S. A multiset S of edges of G is Eulerian if every vertex in G is incident with an even number of edges in S (counting multiplicities if S is a multiset).We shall use the following well known fact: A multiset S of edges of a multigraph G are edges of some closed walk in G (that uses each edge in S the same number of times as its multiplicity) if and only if S is Eulerian and G(S) is connected.
If a multiset of edges S in G can be extended to an Eulerian multiset by adding some edges from a multiset T , then the number of edges from T that has to be added to S is bounded by |V (G)| 2 as is shown in the following lemma.
Lemma 11 Let S, T be multisets of edges of a multigraph G on k vertices.If S can be extended to an Eulerian multiset by adding some edges in T , then this can be done with at most k 2 edges.
Proof: Let T be a subset of T such that S ∪ T is Eulerian.Let T be the subset of edges in T constructed as follows.For every two vertices u and v of G such that T contains an odd number of edges joining u and v, put into T an arbitrary edge from T connecting u and v. Since, for a vertex v ∈ V (G), the degree of v in G(T ) and the degree of v in G(T ) have the same parity, we have that S ∪ T is also Eulerian.Since there are at most k 2 pairs of vertices of G, we have that |T | ≤ k 2 .
In the proof of Lemma 13, we will use the following technical lemma that says that we can always find a small number of cycles in an Eulerian multiset S of edges of K such that the rest of S contains an even number of edges of every color.
Lemma 12 Let S be an Eulerian multiset of edges in K. Let R be the set of colors p such that there is an odd number of edges in S with color p.Then there is a collection of k ≤ t cycles C 1 , . . ., C k in K such that ∪ k i=1 E(C) = T ⊆ S (where the union is a union of multisets) and there is an odd number of edges of color p in T if and only if p ∈ R.

5 case r is a leaf and its neighbor u is not labelled 6 ρ
H ←− Descriptor(H − r, u).

7 case r is in a cycle C and is of degree two 8 foreach v ∈ V (C) \ {r} do 9 Let 10 ρ 11 Use 12 case r is a cutvertex 13 foreach r-bridge B i do 14 ρConstruct the bridge vector b from ρ Bi . 16 Compute m b . 17 Use
B v be the union of all v-bridges that do not contain C. Bv ←− Descriptor(B v , v).Lemma 7 to compute ρ H from ρ Bv .Bi ←− Descriptor(B i , r).15 Lemma 8 to compute ρ H from m b and ρ Bi .

Lemma 9
Let b be a bridge vector.Then for every A, B ∈ L, m b [A, B] ≤ 2t + 2. Proof: For every type p ∈ {1, . . ., t}, there are labels A p , B p such that p[A p , B p ] = 0.By Lemma 2, p[B p , A p ] = 0 as well.Let k = sum(b) and let P = (p 1 , . . ., p k ) be the sequence of types in b in the increasing order.Let R = (L 0 , . . ., L k ) be the sequence of labels such that L 0 = A, L k = B, and for