Almost Envy-Free Allocations with Connected Bundles

We study the existence of allocations of indivisible goods that are envy-free up to one good (EF1), under the additional constraint that each bundle needs to be connected in an underlying item graph. If the graph is a path and the utility functions are monotonic over bundles, we show the existence of EF1 allocations for at most four agents, and the existence of EF2 allocations for any number of agents; our proofs involve discrete analogues of the Stromquist's moving-knife protocol and the Su--Simmons argument based on Sperner's lemma. For identical utilities, we provide a polynomial-time algorithm that computes an EF1 allocation for any number of agents. For the case of two agents, we characterize the class of graphs that guarantee the existence of EF1 allocations as those whose biconnected components are arranged in a path; this property can be checked in linear time.


Introduction
A famous literature considers the problem of cake-cutting (Brams and Taylor, 1996;Robertson and Webb, 1998;Procaccia, 2016). There, a divisible heterogeneous resource (a cake, usually formalized as the interval [0, 1]) needs to be divided among n agents. Each agent has a valuation function over subsets of the cake, usually formalized as an atomless measure over [0,1]. The aim is to partition the cake into n pieces, and allocate each piece to one agent, in a "fair" way. By fair, we will mean that the allocation is envy-free: no agent thinks that another agent's piece is more valuable than her own.
When there are two agents, the classic procedure of cut-and-choose can produce an envy-free division: a knife is moved from left to right, until an agent shouts to indicate that she thinks the pieces to either side are equally valuable. The other agent then picks one of the pieces, leaving the remainder for the shouter. As is easy to see, the result is an envy-free allocation. For three or more agents, finding an envy-free division has turned out to be much trickier. An early result by Dubins and Spanier (1961) used Lyapunov's Theorem and measure-theoretic techniques to show, non-constructively, that an envy-free allocation always exists. However, as Stromquist (1980) memorably writes, "their result depends on a liberal definition of a 'piece' of cake, in which the possible pieces form an entire σ-algebra of subsets. A player who only hopes for a modest interval of cake may be presented instead with a countable union of crumbs." In many applications of resource allocation (such as land division, or the allocation of time slots), agents have little use for a severely disconnected piece of cake. Stromquist (1980) himself offered a solution, and gave a new non-constructive argument (using topology) which proved that there always exists an envy-free division of the cake into intervals. Forest Simmons later observed that the proof could be simplified by using Sperner's lemma, and this technique was subsequently presented in a paper by Su (1999). For the three-agent case, Stromquist (1980) also presented an appealing moving-knife procedure that more directly yields a connected envy-free allocation. For n 4 agents, no explicit procedures are known to produce a connected envy-free allocation (i.e., an allocation where the cake is cut in exactly n − 1 places). However, for n = 4, several moving-knife procedures exist that only need a few cuts; for example, the Brams-Taylor-Zwicker (1997) procedure requires 11 cuts, and a protocol of Barbanel and Brams (2004) requires 5 cuts.
In many applications, the resources to be allocated are not infinitely divisible, and we face the problem of allocating indivisible goods. Most of the literature on indivisible goods has not assumed any kind of structure on the item space, in contrast to the rich structure of the interval [0, 1] in cake-cutting. Thus, there has been little attention on minimizing the number of "cuts" required in an allocation. However, when the items have a spatial or temporal structure, this consideration is important.
In this paper, we study the allocation of items that are arranged on a path or other structure, and impose the requirement that only connected subsets of items may be allocated to the agents. Formally, we work in the model of Bouveret et al. (2017), who assume that the items form the vertex set of a graph G, and a bundle is connected if it induces a connected subgraph of G. For example, such connectivity requirements are encountered in allocation problems in which the items correspond to indivisible pieces of an underlying region of Euclidean space (such as plots of land), and each allocated bundle (i.e., a collection of pieces) must be a connected portion of the space. We are most interested in the case when G is a path, on which connectivity requirements are natural when the items are time slots, for example. In practice, connectivity may not be a hard constraint, and agents may find bundles with few connected components acceptable, but we will not consider such relaxations.
In the work of Bouveret et al. (2017), it became apparent that techniques from cake-cutting can be usefully ported to achieve good connected allocations in the indivisible case. For example, moving-knife procedures that achieve proportionality in cake-cutting have analogues that produce allocations that satisfy the maximin share guarantee (Budish, 2011). 1 Do envy-free procedures for cake-cutting also translate to the indivisible case? Of course, in general, it is impossible to achieve envy-freeness with indivisibilities (consider two agents and a single desirable item), but we can look for approximations. A relaxation of envy-freeness that has been very influential recently is envy-freeness up to one good (EF1), introduced by Budish (2011). It requires that an agent's envy towards another bundle vanishes if we remove some item from the envied bundle. In the setting without connectivity constraints and with additive valuations, the maximum Nash welfare solution satisfies EF1, as does a simple round-robin procedure . The well-known envy-graph algorithm (Lipton et al., 2004) also guarantees EF1. However, none of these procedures respects connectivity constraints.
When items are arranged on a path, we prove that connected EF1 allocations exist when there are two, three, or four agents. As was necessary in cake-cutting, we use successively more complicated tools to establish these existence results. For two agents, there is a discrete analogue of cut-and-choose that satisfies EF1. In that procedure, a knife moves across the path, and an agent shouts when the knife reaches what we call a lumpy tie, that is when the bundles to either side of the knife have equal value up to one item. For three agents, we design an algorithm mirroring Stromquist's moving-knife procedure which guarantees EF1. For four agents, we show that Sperner's lemma can be used to prove that an EF1 allocation exists, via a technique inspired by the Simmons-Su approach, and an appropriately triangulated simplex of connected partitions of the path. For five or more agents, we were not able to establish the existence of EF1 allocations on a path, but we can show (again via Sperner's lemma) that EF2 allocations exist, strengthening a prior result of Suksompong (2019). We also show that if all agents have the same valuation function over bundles, then an egalitarian-welfare-optimal allocation, after suitably reallocating some items, is EF1.
These existence results require only that agents' valuations are monotonic (they need not be additive), and in addition, ensure that the constructed allocation satisfies the maximin share guarantee (see Appendix A.1). Moreover, the fairness guarantee of our algorithms is slightly stronger than the standard notion of EF1: in the returned allocations, envy can be avoided by removing just an outer itemone whose removal leaves the envied bundle connected. Computationally speaking, all our existence results are constructive in the weak sense that an EF1 allocation can be found by iterating through all O(m n ) connected allocation (this stands in contrast to cake-cutting where we cannot iterate through all  Table 1.: Overview of our results for paths. Here, n denotes the number of agents and m the number of items. Agents' valuations are assumed to be monotone. The mark represents that a connected allocation satisfying the corresponding fairness notion exists. When no reference is given, the result follows from other results in the table. possibilities). While we know of no faster algorithms to obtain an EF1 or EF2 allocation in the cases where we appeal to Sperner's lemma, our other procedures (for two or three agents, or for identical valuations) can all be implemented efficiently to produce a fair allocation in polynomial time. We summarize our results concerning paths in Table 1.
In simultaneous and independent work, Oh et al. (2019) designed protocols to find EF1 allocations in the setting without connectivity constraints, aiming for low query complexity. They found that adapting cake-cutting protocols to the setting of indivisible items arranged on a path is an especially potent way to achieve low query complexity. This led them to also study a discrete version of the cut-and-choose protocol which achieves connected EF1 allocations for two agents, and they found an alternative proof that an EF1 allocation on a path always exists with identical valuations. They also present a discrete analogue of the Selfridge-Conway procedure which, for three agents with additive valuations, produces an allocation of a path into bundles that have a constant number of connected components. However, they do not study connected allocations on graphs that are not paths, and they do not consider the case of (non-identical) general valuations with more than two agents.
A recurring theme in our algorithms is the specific way that the moving knives from cake-cutting are rendered in the discrete setting. While one might expect knives to be placed over the edges of the path, and 'move' from edge to edge, we find that this movement is too 'fast' to ensure EF1 (see also footnote 5 regarding EF2). Instead, our knives alternate between hovering over edges and items. When a knife hovers over an item, we imagine the knife's blade to be 'thick': the knife covers the item, and agents then pretend that the covered item does not exist. These intermediate steps are useful, since they can tell us that envy will vanish if we hide an item from a bundle.
What about graphs G other than paths? Our existential results for paths immediately generalize to traceable graphs (those that contain a Hamiltonian path), since we can run the algorithms pretending that the graph only consists of the Hamiltonian path. For the two-agent case, we completely characterize the class of graphs that guarantee the existence of EF1 allocations: Our discrete cut-and-choose protocol can be shown to work on all graphs G that admit a bipolar numbering, which exists if and only if the biconnected components (blocks) of G can be arranged in a path. By constructing counterexamples, we prove that no graph failing this condition (for example, a star) guarantees EF1, even for identical, additive, binary valuations. For the case of three or more agents, it is a challenging open problem to characterize the class of graphs guaranteeing EF1 (or even to find an infinite class of non-traceable graphs that guarantees EF1).

Preliminaries
For each natural number s ∈ N, write [s] = {1, 2, . . . , s}. Let N = [n] be a finite set of agents and G = (V, E) be an undirected finite graph, where V = {v 1 , v 2 , . . . , v m }. The vertices in V correspond to items. A subset I of V is connected if it induces a connected subgraph of G. We write C(V ) for the set of connected subsets of V . We call a set I ∈ C(V ) a (connected) bundle. Each agent i ∈ N has a valuation function u i : C(V ) → R over connected bundles, which we will always assume to be monotonic, that is, X ⊆ Y implies u i (X) u i (Y ). We also assume that u i (∅) = 0 for each i ∈ N . Monotonicity implies that items are goods; we do not consider bads (or chores) in this paper. We say that an agent i ∈ N weakly prefers bundle X to bundle Y if u i (X) u i (Y ). 2 A (connected) allocation A : N → C(V ) assigns each agent i ∈ N a connected bundle A(i) ∈ C(V ) such that each item occurs in exactly one bundle, i.e., i∈N A(i) = V and A(i) ∩ A(j) = ∅ when i = j. We often write I i for the bundle A(i) assigned to agent i. We say that the agents have identical valuations if, for all i, j ∈ N and every bundle I ∈ C(V ), we Many examples in this paper will use identical additive valuations, and will take G to be a path. In this case, we use a shorthand to specify these examples; the meaning of this notation should be clear. For example, we write "2-1-3-1" to denote an instance with four items v 1 , v 2 , v 3 , v 4 arranged on a path, and where u i ({v 1 }) = 2, . . . , u i ({v 4 }) = 1 for each i. For such an instance, an allocation will be written as a tuple, e.g., (2, 1-3-1) denoting an allocation allocating bundles {v 1 } and {v 2 , v 3 , v 4 }, noting that with identical valuations it does not usually matter which agent receives which bundle.
An allocation A is envy-free if u i (A(i)) u i (A(j)) for every pair i, j ∈ N of agents, that is, if every agent thinks that their bundle is at least as good as any other bundle in the allocation. It is well-known that an envy-free allocation may not exist (consider two agents and one good). The main fairness notion that we study is a version of envy-freeness up to one good (EF1), a relaxation of envy-freeness introduced by Budish (2011), adapted to the model with connectivity constraints. This property states that an agent i will not envy another agent j after we remove some item from j's bundle. Since we only allow connected bundles in our set-up, we may only remove an item from A(j) if removal of this item leaves the bundle connected.
Definition 2.1 (EF1: envy-freeness up to one outer good). An allocation A satisfies EF1 if, for any pair i, j ∈ N of agents, either A(j) = ∅ or there is a good v ∈ A(j) such that A(j) \ {v} is connected and In the instance 2-1-3-1 for two agents, the allocation (2-1, 3-1) is EF1, since the left agent's envy can be eliminated by removing the item of value 3 from the right-hand bundle. However, the allocation (2, 1-3-1) fails to be EF1 according to our definition, since eliminating either outer good of the right bundle does not prevent envy. 3 Definition 2.2. A graph G guarantees EF1 for n agents if, for all possible monotonic valuations for n agents, there exists some connected allocation that is EF1. A graph G guarantees EF1 for n agents and a restricted class of valuations if, for all allowed valuations, a connected EF1 allocation exists.
For reasoning about EF1 allocations, let us introduce a few shorthands. Given an allocation A we will say that i ∈ N does not envy j Thus, an allocation A satisfies EF1 if and only if u i (A(i)) u − i (A(j)) for any pair i, j ∈ N of agents. As we show in the appendix in Example A.5, allocations satisfying a strengthened version of EF1 called envy-freeness up to the least good (EFX)  may not exist on a path.
Given an ordered sequence of the vertices P = (v 1 , v 2 , . . . , v m ), and j, k ∈ [m] with j k, we write With a little abuse of notation, we often identify a subsequence P (v j , v k ) with the bundle of the corresponding vertices. Let L(v j ) = P (v 1 , v j−1 ) be the subsequence of vertices strictly left of v j and R(v j ) = P (v j+1 , v m ) be the subsequence of vertices strictly right of v j . When graph G is a path, we always implicitly assume that its vertices v 1 , v 2 , . . . , v m are numbered from left to right according to the order they appear along the path, so that the set of the edges of G is {{v j , v j+1 } : 1 j < m}. Each connected bundle in the path clearly corresponds to a subpath or subsequence of the vertices. A Hamiltonian path of a graph G is a path that visits all the vertices of the graph exactly once. A graph is traceable if it contains a Hamiltonian path.

EF1 existence for two agents
In cake-cutting for two agents, the standard way of obtaining an envy-free allocation is the cut-and-choose protocol: Alice divides the cake into two equally-valued pieces, and Bob selects the piece he prefers; the other piece goes to Alice. The same strategy almost works in the indivisible case when items form a path; the problem is that Alice might not be able to divide the items into two exactly equal pieces. Instead, we ask Alice to divide the items into pieces that are equally valued "up to one good". The formal version is as follows. For a sequence of vertices P = (v 1 , v 2 , . . . , v m ) and an agent i, we say that v j is the lumpy tie over P for agent i if j is the smallest index such that (3.1) For example, when i has additive valuations 1-3-2-1-3-1, then the third item (of value 2) is the lumpy tie for i, since 1 + 3 + 2 1 + 3 + 1 and 2 + 1 + 3 + 1 1 + 3. The lumpy tie always exists: taking j to be the smallest index such that u i (L(v j ) ∪ {v j }) u i (R(v j )) (which exists as the inequality holds for j = m by monotonicity), the first part of (3.1) holds. If j = 1, the second part of (3.1) is immediate by monotonicity.
Using lumpy ties, our discrete version of the cut-and-choose protocol is specified as follows.
• Step 2. Bob chooses a weakly preferred bundle among L(v j ) and R(v j ). • Step 3. Alice receives the bundle of all the remaining vertices, including v j .
Intuitively, the protocol allows Alice to select an item v j that she will receive for sure, with the advice that the two pieces to either side of v j should have almost equal value to her. Then, Bob is allowed to choose which side of v j he wishes to receive. In our example with valuations 1-3-2-1-3-1, Alice selects the lumpy tie of value 2, then Bob chooses the bundle 1-3-1 to the right and receives it, and Alice receives the bundle 1-3-2. The result is EF1. This is true in general, and also if valuations are not identical.
Proposition 3.2. When G is a path and there are n = 2 agents, the discrete cut-and-choose protocol yields an EF1 allocation.
Proof. Clearly, the protocol returns a connected allocation. The returned allocation satisfies EF1: Bob does not envy Alice up to item v j , since Bob receives his preferred bundle among L(v j ) and R(v j ). Also, by (3.1), Alice does not envy Bob, since Alice either receives the bundle L(v j ) ∪ {v j } which she weakly prefers to Bob's bundle R(v j ), or she receives the bundle R(v j ) ∪ {v j }, which she weakly prefers to Bob's bundle L(v j ).
Proposition 3.2 implies that an EF1 allocation always exists on a path. Hence, an EF1 allocation exists for every traceable graph G: simply use the discrete cut-and-choose protocol on a Hamiltonian path of G. In fact, the discrete cut-and-choose protocol works on a broader class of graphs: We only need to require that the vertices of the graph can be numbered in a way that the allocation resulting from the discrete cut-and-choose protocol is guaranteed to be connected. Since the protocol always partitions the items into an initial and a terminal segment of the sequence, such a numbering needs to satisfy the following property.
Definition 3.3. A bipolar numbering of a graph G is an ordering (v 1 , v 2 , . . . , v m ) of its vertices such that for all j ∈ [n], the sets L(v j ) ∪ {v j } and R(v j ) ∪ {v j } are connected in G.
In a slightly different context, bipolar numberings are known as st-numberings and turn out to be useful in algorithms for testing planarity and for graph drawing (Lempel et al., 1967;Even and Tarjan, 1976;Tarjan, 1986). The more common (equivalent) definition is phrased to say that a numbering is bipolar if, for every j ∈ [n], the vertex v j has a neighbor that appears earlier in the sequence, and a neighbor that appears later in the sequence.
Clearly, every traceable graph has a bipolar numbering, since we can just use a Hamiltonian path. However, there are also non-traceable graphs that admit a bipolar numbering. Figure 1 shows some examples. Proposition 3.4. When there are n = 2 agents, then the discrete cut-and-choose protocol run on a bipolar numbering of G yields an EF1 allocation.
Proof. The discrete cut-and-choose protocol returns an allocation whose bundles are either initial or terminal segments of the ordered sequence (v 1 , v 2 , . . . , v m ). By definition of a bipolar numbering, such an allocation is connected, and it is EF1 by the same argument as in Proposition 3.2.
It is clear that the discrete cut-and-choose protocol cannot be extended to graphs other than those admitting a bipolar numbering. However, it could be that a different protocol is able to produce EF1 allocations on other graphs. In the remainder of this section, we prove that this is not the case: for n = 2 agents, a connected graph G guarantees the existence of an EF1 allocation if and only if it admits a bipolar numbering. This completely characterizes the class of graphs that guarantee EF1 existence in the two-agent case. 4 For a different number of agents, the class of graphs guaranteeing an EF1 allocation will be different. In particular, the star with three leaves does not guarantee an EF1 allocation for two agents (as it does not have a bipolar numbering, see below), but one can check that this star does guarantee an EF1 allocation for three or more agents (see Example A.6 in the appendix).

Characterization of graphs guaranteeing EF1 for two agents
Based on a known characterization of graphs admitting a bipolar numbering, we characterize this class in terms of forbidden substructures. We then show that these forbidden structures are also forbidden for EF1: if a graph contains such a structure, we can exhibit an additive valuation profile for which no EF1 allocation exists.
As a simple example, consider the star with three leaves, which is the smallest connected graph that does not have a bipolar numbering.
Take two agents with identical additive valuations that value each item at 1. Any connected allocation must allocate three items to one agent, and a single item to the other agent. Then the latter agent envies the former agent, even up to one good. This star is an example of a forbidden substructure called a trident, which takes one of two forms, illustrated in Figure 2.
Definition 3.5. A graph G contains a trident if either (a) there is a vertex s whose removal from G leaves three or more connected components (a type I trident), or (b) there are subgraphs C, P 1 , P 2 , P 3 of G such that (i) P 1 , P 2 , P 3 are vertex-disjoint, (ii) each P i contains at least two vertices, (iii) C has exactly one contact vertex s i in common with P i , i = 1, 2, 3, and (iv) for i = 1, 2, 3, removal of vertex s i from G disconnects P i \ {s i } from C \ {s i } (hence from the other two P j ) in G (a type II trident). C P 1 P 3 P 2 Figure 2.: A type I trident (left) and a type II trident (right).
We will prove that a graph G fails to admit a bipolar numbering, and fails to guarantee EF1 for two agents, if and only if G contains a trident. To reason about these structures, it is useful to consider the standard concept of the block decomposition of a graph (see, e.g., the textbook Bondy and Murty, 2008, Sec. 5.2).
Equivalently, a block of a graph G can be defined as a maximal subgraph of G where each pair of vertices lie on a common cycle (Bondy and Murty, 2008). Given a connected graph G, we define a bipartite graph B(G) with bipartition (B, S), where B is the set of blocks of G and S is the set of cut vertices of G; a block B and a cut vertex v are adjacent in B(G) if and only if B includes v. Since every cycle of a graph is included in some block, the graph B(G) is a tree: Lemma 3.7 (e.g., Bondy and Murty, 2008, Prop. 5.3). Let G be a connected graph. Then • any two blocks of G have at most one cut vertex in common; • the set of blocks forms a decomposition of G; and • the graph B(G) is a tree.
Thus, for a connected graph G, we call B(G) the block tree of G. It turns out that G admits a bipolar numbering if and only if B(G) is a path. For example, the graphs shown in Figure 1 all have their blocks arranged in a path (so that B(G) is a path), as shown in Figure 3. Lemma 3.8. A graph G admits a bipolar numbering if its block tree B(G) is a path. Proof. Lempel et al. (1967) show that G admits a bipolar numbering if there are s, t ∈ V such that adding an edge {s, t} to G makes it biconnected. If B(G) is a path, let B 1 and B 2 be the leaf blocks at the ends of the path B(G). Take any s ∈ B 1 and t ∈ B 2 . If we add the edge {s, t} to G, the graph becomes biconnected. Hence, G admits a bipolar numbering.
There is a linear-time algorithm based on depth-first search to construct a bipolar numbering for any biconnected graph (Even and Tarjan, 1976;Tarjan, 1986), and one can also calculate the block tree B(G) of a given graph in linear time (Hopcroft and Tarjan, 1973). Thus, in linear time, we can compute a bipolar numbering of a graph or report that none exists. Clearly, given a bipolar numbering, the discrete cut-and-choose protocol can also be run in linear time.
Next, we show that if B(G) is not a path, then G cannot guarantee EF1. The proof constructs explicit counter-examples, which have a very simple structure. We say that additive valuations u i are binary if Lemma 3.9. Let G be a connected graph.
• If the block tree B(G) of G is not a path, then G contains a trident.
• If G contains a trident, then there exist identical, additive, binary valuations over G for two agents such that no connected allocation is EF1.
is not a path, then it contains a vertex with at least three neighbors, and thus either (a) there is a cut vertex s adjacent to three blocks B 1 , B 2 , and B 3 ; or (b) there is a block B adjacent to three different cut vertices s 1 , s 2 , and s 3 .
Note that in both cases, all blocks contain at least two vertices each, as maximality guarantees that a block in a connected graph G never consists of a single vertex, unless G itself has only one vertex. Thus, in case (a), G contains a type I trident. In case (b), the cut vertices s 1 , s 2 , and s 3 serve as the contact vertices in the earlier definition of type II tridents and are adjacent to blocks that serve as the subgraphs P 1 , P 2 , and P 3 . This proves the first part.
To prove the second part, we construct identical additive valuations that do not admit an EF1 allocation. If G contains a type I trident, let s be the corresponding cut vertex, and choose vertices v 1 , v 2 , v 3 from each of three different connected components that remain after s is deleted from G. The two agents have utility 1 for each of s, v 1 , v 2 , and v 3 , and 0 for the remaining vertices. Now take any connected allocation (I 1 , I 2 ). One of the bundles, say I 1 , includes the cut vertex s. Then I 2 can contain at most one of the vertices v 1 , v 2 , v 3 , since I 2 is connected and does not contain s yet any path between distinct v i and v j goes through s. Hence u i (I 2 ) 1. Now, the bundle I 1 contains s and at least two of v 1 , v 2 , v 3 , so u i (I 1 ) 3. Thus, the allocation is not EF1.
Suppose G contains a type II trident consisting of subgraphs C, P 1 , P 2 , P 3 with contact vertices s 1 , s 2 , s 3 . Then for i = 1, 2, 3 choose a vertex v i = s i from P i . The two agents have utility 1 for each of s 1 , s 2 , s 3 , v 1 , v 2 , and v 3 , and 0 for the remaining vertices. Now take any connected allocation (I 1 , I 2 ). One of the bundles, say I 1 , contains at least two contact vertices s i and the other contains at most one contact vertex s i . Say that s 1 , s 2 ∈ I 1 . Now, G \ {s 1 , s 2 } has at least three connected components, and since I 2 is connected, it must be contained in one of these components. But each component contains at most two vertices with utility 1, so u i (I 2 ) 2. Since there are six vertices with utility 1 in total, u i (I 1 ) 4. Thus, the allocation is not EF1.
Combining these results, we obtain the promised characterization.
Theorem 3.10. The following conditions are equivalent for every connected graph G: 1. G admits a bipolar numbering.
2. G guarantees EF1 for two agents.
3. G guarantees EF1 for two agents with identical, additive, binary valuations.
4. G does not contain a trident.
The equivalence (2) ⇔ (3) is noteworthy and perhaps surprising: It is often easier to guarantee fairness when agents' valuations are identical, yet in terms of the graphs that guarantee EF1 for two agents, there is no difference between identical and non-identical valuations. Intriguingly, even for more than two agents, we do not know of a graph which guarantees EF1 for identical valuations, but fails it for non-identical valuations.

EF1 existence for three agents: A moving-knife protocol
We will now consider the case of three agents. Stromquist (1980) designed a protocol that results in an envy-free contiguous allocation of a divisible cake. We now give a brief outline of the protocol, illustrated by A referee holds a sword over the cake. Each of the three agents holds their own knife over the portion of the cake to the right of the sword, positioning it so that this portion is divided into two pieces they judge to have the same value. Now, initially, the sword is at the left end of the cake. It starts moving at a constant speed from left to right, while the agents continuously move their knives to keep dividing the right-hand portion into equally-valued pieces. At some point (when the leftmost piece becomes valuable enough), one of the agents shouts "cut", and the cake will be cut twice: once by the sword, and once by the middle one of the three knives. Agents shout "cut" as soon as the left piece is a highest-valued piece among the three. The agent who shouts receives the left piece. The remaining agents each receive a piece containing their knife. The resulting allocation is envy-free, since the agent receiving the left piece prefers it to the other pieces, and the other agents who are not shouting receive at least half the value of the part of the cake to the right of the sword.
Let G be a path, P = (v 1 , v 2 , . . . , v m ). There are several difficulties in translating Stromquist's continuous procedure to the discrete setting for G. First, agents need to divide the piece to the right of the sword in half, and this might not be possible exactly given indivisibilities; but this can be handled using our concept of lumpy ties from Section 3. Next, when the sword moves one item to the right, the lumpy ties of the agents may need to jump several items to the right, for example, because the new member of the leftmost bundle is very valuable. To ensure EF1, we will need to smoothen these jumps, so that the middle piece grows one item at a time. Also, it will be helpful to have the sword move in half-steps: it alternates between being placed between items (so it cuts the edge between the items), and being placed over an item, in which case the sword covers the item and agents ignore that item. Finally, while the sword covers an item, we will only terminate if at least two agents shout to indicate that they prefer the leftmost piece; this will ensure that there is an agent who is flexible about which of the bundles they are assigned. The algorithm moves in steps, and alternates between moving the sword, and updating the lumpy ties.
In our formal description of the algorithm, we do not use swords and knives. Instead, we maintain three bundles L, M , and R that can be seen as resulting from a certain configuration this cutting implements. We also need a few definitions. For a subsequence of vertices P (v s , v r ) = (v s , v s+1 , . . . , v r ) and an agent i, recall that v j (s j r) is the lumpy tie over P (v s , v r ) for i if j is the smallest index such that (4.1) Here, the definitions of L(v j ) and R(v j ) apply to the subsequence P (v s , v r ). The lumpy tie always exists by the discussion after equation (3.1). Each of the three agents has a lumpy tie over P (v s , v r ); a key concept for us is the median lumpy tie which is the median of the lumpy ties of the three agents, where the median is taken with respect to the ordering of P (v s , v r ). We say that i ∈ N is a left agent (respectively, a middle agent or a right agent) over P (v s , v r ) if the lumpy tie for i appears strictly before (respectively, is equal to, or appears strictly after) the median lumpy tie. Note that by definition of the median, there is at most one left agent, at most one right agent, and at least one middle agent. Suppose that the median lumpy tie over the subsequence P (v s , v r ) is v j , and let i be an agent. Then using the definitions of lumpy tie and left/right agents, we find that Given the median lumpy tie v j over P (v s , v r ), and a two- • if i is a middle agent, then agent k receives k's preferred bundle among L(v j ) and R(v j ), and agent i receives the other bundle along with v j .
Using (4.1) and (4.2), we see that Lumpy(S, v j , P (v s , v r )) is an EF1 allocation: The algorithm is specified in Definition 4.2. It alternately moves a left pointer (in Steps 2 and 3) and a right pointer r (in Step 4). It also maintains bundles L, M , and R during the execution of the algorithm.
Definition 4.2. The discrete moving-knife protocol for n = 3 agents on a sequence P = (v 1 , v 2 , . . . , v m ) proceeds as follows. We say that an agent i ∈ N is a shouter if u i (L) u i (M ) and u i (L) u i (R).
• Step 1. Initialize = 0 and set r so that v r is the median lumpy tie over the subsequence P (v 2 , v m ). Initialize • Step 2. Add an additional item to L, i.e., set = + 1 and L = {v 1 , v 2 , . . . , v }. If no agent shouts, go to Step 3. If some agent s left shouts, s left receives the left bundle L. Allocate the remaining items according to Lumpy(N \ {s left }, v r , P (v +1 , v m )). • Step 3. Delete the leftmost point of the middle bundle, i.e., set M = {v +2 , v +3 , . . . , v r−1 }. If the number of shouters is smaller than two, go to Step 4. If at least two agents shout, we show (next page) that there is a shouter s who is a middle agent over P (v +1 , v m ). Then, allocate L to a shouter s left distinct from s. Let the agent c distinct from s and s left choose his preferred bundle among {v +1 } ∪ M and {v r } ∪ R. Agent s receives the other bundle. • Step 4. If v r is the median lumpy tie over P (v +2 , v m ), directly move to the following cases (a)-(d).
If v r is not the median lumpy tie over (a) If at least two agents shout, find a shouter s who did not shout at the previous step. If there is a shouter s left who shouted at the previous step, s left receives L; else, give L to an arbitrary shouter s left distinct from s. The agent c distinct from s and s left choose his preferred bundle among {v +1 } ∪ M and {v r } ∪ R, breaking ties in favor of the former option. Agent s receives the other bundle. (b) If v r is the median lumpy tie over P (v +2 , v m ) and only one agent s left shouts, give L ∪ {v +1 } to s left and allocate the rest according to Lumpy(N \ {s left }, v r , P (v +2 , v m )). (c) If v r is the median lumpy tie over P (v +2 , v m ) but no agent shouts, go to Step 2.
(d) Otherwise v r is not the median lumpy tie over P (v +2 , v m ): Repeat Step 4.
Theorem 4.3. The moving-knife protocol finds an EF1 allocation for three agents and runs in O(m) time, when G is a path.
Proof. The algorithm is well-defined -there is one place where this is not immediate: If two agents shout in Step 3, the algorithm description claims that there is a shouter who is a middle agent over the subsequence P (v +1 , v m ). Suppose for the moment that there is a shouter i who is a right agent. Due to (4.2), we have , and either case is a contradiction. Hence neither of the at least two shouters of Step 3 is a right agent, so at least one shouter is a middle agent, since there is at most one left agent. The algorithm terminates and returns an allocation, since the bundle L grows throughout the algorithm until eventually, at least two agents will think that L is a best bundle and thus will shout and thereby terminate the algorithm. We will now consider every possible way that the algorithm could have terminated, and show that the resulting allocation is EF1.
• Agent s left receives L and does not envy the other agents (up to good v r ) since s left is a shouter.
• An agent i who is not a shouter does not envy s left because i prefers either M or R to L, and hence by Lemma 4.1 receives a bundle preferred to L. Agent i also does not envy the other agent j = s left up to one good by Lemma 4.1.
• An agent i = s left who is a shouter does not envy s left up to one good: If this is the first time Step 2 was performed, then L = {v 1 }, so i does not envy s left up to v 1 . Otherwise, the last step was an iteration of Step 4(c), where by definition of Step 4(c) no-one shouted. Since i did not shout during Step 4(c), and Step 2 did not change the bundles M and R, then i strictly prefers either M or R to the left bundle L \ {v } of Step 4(c). By Lemma 4.1, agent i gets a bundle at least as good as M or R. Thus, i does not envy s left up to v . Also by Lemma 4.1, agent i does not envy the other agent j = s left up to one good.
• Agent s left receives L and, because s left shouted, does not envy the bundle {v +1 } ∪ M up to good v +1 , and does not envy the bundle {v r } ∪ R up to good v r .
• Agent c gets his preferred bundle among {v +1 } ∪ M and {v r } ∪ R, and so does not envy agent s who receives the other bundle. Further, agent c does not envy agent s left since c did not shout at the last Step 2 (where no-one shouted), which, since bundle L did not change in Step 3, means that c prefers either {v +1 } ∪ M or R to L, and hence also prefers his chosen bundle to L.
• Agent s is a middle agent, so the lumpy tie of s over P (v +1 , v m ) is v r , and hence by (4.1), Now, agent s did not shout at the preceding Step 2 (when no-one shouted). However, s does shout after deleting v +1 from M . Since L and R have not changed, the reason s did not shout at Step 2 was that L is worse than the middle bundle during Step 2, so Step 4(a). We first prove that if i is a shouter who did not shout in the previous step, then In the previous step (which was either Step 3 or Step 4), the middle bundle was M \ {v r−1 } and the right bundle was {v r } ∪ R. (While Step 4 allows for the possibility that the middle and right bundles are not changed in Step 4, this is not the case if we enter Step 4(a): if the bundles are unchanged and two agents shout, these agents already shouted in Step 3, contradicting that we did not terminate then.) Since i did not shout with the middle and right bundles of the previous step, we have Since i is a shouter, u i (L) u i (M ), so that the first case is impossible by monotonicity. Hence • Agent s left receives L and does not envy other agents up to one good like in Step 3. • Agent s does not envy others up to one good: -Suppose agent c strictly prefers {v r }∪R to {v +1 }∪M . Then agent c's lumpy tie over P (v +1 , v m ) appears at or after v r by definition of the lumpy tie. As we argued before, the bundles M and R were changed in the execution of Step 4, and r was increased by 1. Thus, v r appears strictly after the median lumpy tie over P (v +1 , v m ). Thus, c is the right agent over P (v +1 , v m ). Hence s is either a left or middle agent over P (v +1 , v m ) since there is at most one right agent. Using Step 4(b).
• Agent s left gets L ∪ {v +1 } and does not envy the other agents (up to good v r ) as s left shouts.
• Any agent i = s left is not a shouter, and thus prefers either M or R to L. Hence by Lemma 4.1 receives a bundle preferred to L, and so does not envy s left up to item v +1 . Agent i also does not envy the other agent j = s left up to one good by Lemma 4.1.
Thus, the allocation returned by any of the steps satisfies EF1. Our algorithm can be implemented in O(m) time: Each of steps 2, 3, and 4 will be executed at most m times (since and r can only be incremented m times). The execution of each step takes constant time: In each step, we need to check which agents shout, and this can be done in a constant number of queries to agents' valuations; also, in Step 4 we need to calculate the lumpy ties of the agents, but this can be done in amortized constant time, since during the execution of the algorithm, the position of each agent's lumpy tie can only move to the right. Finally, when enough agents shout, we can clearly compute and return the final allocation in O(m) time.

EF2 existence for any number of agents
For two or three agents, we have seen algorithms that are guaranteed to find an EF1 allocation on a path (and on traceable graphs). Both algorithms were adaptations of procedures that identify envy-free divisions in the cake-cutting problem. For the case of four or more agents, we face a problem: there are no known procedures that find connected envy-free division in cake-cutting if the number of agents is larger than three. However, in the divisible setting, a non-constructive existence result is known: Su (1999) proved, using Sperner's lemma, that for any number of agents, a connected envy-free division of a cake always exists. One might try to use this result as a black box to obtain a fair allocation for the indivisible problem on a path: Translate an indivisible instance with additive valuations into a divisible cake (where each item corresponds to a region of the cake), obtain an envy-free division of the cake, and round it to get an allocation of the items. Suksompong (2019) followed this approach and showed that the result is an allocation where any agent i's envy u i (A(j)) − u i (A(i)) is at most 2u max , where u max is the maximum valuation for a single item.
In this section, rather than using Su's (1999) result as a black box, we directly apply Sperner's lemma to the indivisible problem. This allows us to obtain a stronger fairness guarantee: We show that on paths (and on traceable graphs), there always exists an EF2 allocation. 5 An allocation is EF2 if any agent's envy can be avoided by removing up to two items from the envied bundle. Again, we only allow removal of items if this operation leaves a connected bundle.
Definition 5.1 (EF2: envy-freeness up to two outer goods). An allocation A satisfies EF2 if, for any pair i, j ∈ N of agents, either |A(j)| 1, or there are two goods u, v ∈ A(j) such that A(j) \ {u, v} is connected and u i (A(i)) u i (A(j) \ {u, v}).
Let us first give a high-level illustration with three agents of how Sperner's lemma can be used to find low-envy allocations.  Given a path P = (a, b, c, d), the family of connected partitions of P can naturally be arranged as the vertices of a subdivided simplex, as in Figure 5.
For each of these partitions, each agent i labels the corresponding vertex by the index of a bundle from that partition that i most-prefers. For example, the top vertex will be labelled as "index 1" by all agents, since they all most-prefer the leftmost bundle in (abcd, ∅, ∅). Now, Sperner's lemma will imply that at least one of the simplices (say the shaded one) is "fully-labeled", which means that the first agent most-prefers the leftmost bundle at one vertex, the second agent most-prefers the middle bundle at another vertex, and the third agent most-prefers the rightmost bundle at the last vertex. Notice that the partitions at the corner points of the shaded simplex are all "similar" to each other (they can be obtained from each other by moving only one item). Hence, we can "round" the corner-partitions into a common allocation A * , say by picking one of the corner partitions arbitrarily and then allocating bundles to agents according to the labels. The resulting allocation has the property that any agents' envy can be eliminated by moving at most one good. 6 The argument sketched above does not yield an EF1 nor even an EF2 allocation. Intuitively, the problem is that the connected partitions at the corners of the fully-labeled simplex are "too far apart", so that no matter how we round the corner partitions into a common allocation A * , some agents' bundles will have changed too much, and so we cannot prevent envy even up to one or two goods. In the following, we present a solution to this problem, by considering a finer subdivision: we introduce n − 1 knives which move in half-steps (rather than full steps), and which might 'cover' an item so that it appears in none of the bundles. The result is that the partial partitions in the corners of the fully-labeled simplex are closer together, and can be successfully rounded into an EF2 allocation A * .
In our approach, we use a specific triangulation (Kuhn's triangulation, Kuhn, 1960). This triangulation has the needed property that the partitions at the corners of sub-simplices are close together, and adjacent partitions can be obtained from each other in a natural way. While this type of triangulation has also been used in cake-cutting, e.g., by Deng et al. (2012), there it was only used to speed up algorithms (compared to the barycentric subdivision used by Su (1999)), not to obtain better fairness properties.

Sperner's lemma
We start by formally introducing Sperner's lemma (cf. Flegg, 1974). Let conv(v 1 , v 2 , . . . , v k ) denote the convex hull of k vectors v 1 , v 2 , . . . , v k . An n-simplex is an n-dimensional polytope which is the convex hull of its n + 1 main vertices. A k-face of the n-simplex is the k-simplex formed by the span of any subset of k + 1 main vertices. A triangulation T of a simplex S is a collection of sub-n-simplices whose union is S with the property that the intersection of any two of them is either the empty set, or a face common to both. Each of the sub-simplices S * ∈ T is called an elementary simplex of the triangulation T . Sperner's lemma states that if L is a proper labeling function, then there exists an elementary simplex of T whose vertices have all different labels.
We will consider a generalized version of Sperner's lemma, proved, for example, by Bapat (1989). In this version, there are n labeling functions L 1 , . . . , L n , and we are looking for an elementary simplex that is fully-labeled for some way of assigning labeling functions to vertices, where we must use each labeling function exactly once. The formal definition is as follows.
Definition 5.2 (Fully-labeled simplex). Let T be a triangulation of an (n − 1)-simplex, and let L 1 , . . . , L n , be labeling functions. An elementary simplex S * of T is fully-labeled if we can write The generalized version of Sperner's lemma that we consider, taken from Bapat (1989), guarantees the existence of a fully-labeled simplex.

Lemma 5.3 (Generalized Sperner's Lemma).
Let T be a triangulation of an (n − 1)-simplex S, and let L 1 , . . . , L n be proper labeling functions. Then there is a fully-labeled simplex S * of T .
6 One can generalize this argument to show that on paths, there exists an allocation A satisfying a weak form of EF1: for any i, j ∈ [n], we have u i (I i ∪ {g i }) u i (I j \ {g j }) for some items g i , g j such that I i ∪ {g i } and I j \ {g j } are connected. For additive valuations, this implies that envy is bounded by u i (g i ) + u i (g j ) 2umax, which is the result of Suksompong (2019).

Existence of EF2 allocations
Suppose that our graph G is a path P = (1, 2, . . . , m), where the items are named by integers. We assume that m n, so that there are at least as many items as agents (when m < n it is easy to find EF1 allocations). Our aim is to cut the path P into n intervals (bundles) I 1 * , I 2 * , . . . , I n * . Throughout the argument, we use superscripts to denote indices of bundles; index 1 refers to the leftmost bundle and index n refers to the rightmost bundle.
Construction of the triangulation. Consider the (n − 1)-simplex 7 We construct a triangulation T half of S m whose vertices V (T half ) are the points x ∈ S m such that each x j is either integral or half-integral, namely, For reasons that will become clear shortly, we call a vector x ∈ V (T half ) a knife position. Using Kuhn's triangulation (Kuhn, 1960;Scarf, 1982;Deng et al., 2012), we construct T half so we can write each elementary simplex S ∈ T half as S = conv(x 1 , x 2 , . . . x n ) and there is a permutation π : where e j = (0, . . . , 1, . . . , 0) is the j-th unit vector. We give an interpretation of (5.2) shortly. Each vertex x = (x 1 , x 2 , . . . , x n−1 ) ∈ V (T half ) of the triangulation T half corresponds to a partial partition A(x) = (I 1 (x), I 2 (x), . . . , I n (x)) of P where I j (x) := {y ∈ {1, 2, . . . , m} : x j−1 < y < x j }, writing x 0 = 1 2 and x n = m + 1 2 for convenience. Intuitively, x specifies the location of n − 1 knives that cut P into n pieces. If x j is integral, that is x j ∈ {1, . . . , m}, then the j-th knife 'covers' the item x j , which is then part of neither I j (x) nor I j+1 (x). This is why A(x) is a partial partition. Since there are only n − 1 knives but m n items, not all items are covered, so at least one bundle is non-empty.
Property (5.2) means that, if we visit the knife positions x 1 , x 2 , . . . x n at the corners of an elementary simplex in the listed order, then at each step exactly one of the knives moves by half a step, and each knife moves only at one of the steps.
Construction of the labeling functions. We now construct, for each agent i ∈ [n], a labeling function L i : V (T half ) → [n]. The function L i takes as input a vertex x of the triangulation T half (interpreted as the partial partition A(x)), and returns a color in [n]. The color will specify the index of a bundle in A(x) that agent i likes the most. Formally, If there are several most-preferred bundles in A(x), ties can be broken arbitrarily. However, we insist that the index L i (x) always corresponds to a non-empty bundle (this can be ensured since A(x) always contains a non-empty bundle, and u i is monotonic).
The labeling functions L i are proper. For each j ∈ [m], the main vertex v j of the simplex S m has the form v j = ( 1 2 , . . . , 1 2 , m + 1 2 , . . . , m + 1 2 ), where the first j − 1 entries are 1 2 and the rest are m + 1 2 . In the partition A(v j ), the bundle I j (v j ) contains all the items, so is most-preferred (since u i is monotonic and by our tie-breaking), and so L i (v j ) = j. Further, any vertex x belonging to the (n − 2)-face of S m not containing v j satisfies x j−1 = x j , and thus in partition A(x), bundle I j (x) is empty, hence is not selected, and so L i (x) = j.
By the generalized version of Sperner's lemma (Lemma 5.3), there exists an elementary simplex S * = conv(x 1 , x 2 , . . . , x n ) of the triangulation T half which is fully-labeled, so that, for some permutation φ : The simplex Sm is affinely equivalent to the standard (n − 1)-simplex ∆ n−1 = {(l 1 , . . . , ln) 0 : l i = 1} via x i = m · (l 1 + l 2 + · · · + l i ) + 1 2 . In these coordinates, l i is the length of the i-th piece (times 1/m). Translation into partial partitions. The fully-labeled elementary simplex S * corresponds to a sequence (A 1 , A 2 , . . . , A n ) of partial partitions of P , which we call the Sperner sequence, where A i = (I 1 i , . . . , I n i ) := A(x i ) for each i ∈ [n]. An example of a Sperner sequence is shown in Figure 6. From the labeling, for each agent i ∈ [n], since L i (x i ) = φ(i), the bundle with index φ(i) in the partition A i is a best bundle for i: Now, for each j ∈ [n], we define the basic bundle B j := I j 1 ∩ · · · ∩ I j n to be the bundle of items that appear in the j-th bundle of every partition in the Sperner sequence. The set of basic bundles is a partial partition. Let us analyze the items between basic bundles. From (5.2), each of the n − 1 knives moves exactly once, by half a step, while passing through the Sperner sequence (A 1 , A 2 , . . . , A n ). Thus, the numbers x j 1 , . . . , x j n take on two different values, one of which is integral and the other half-integral. We write y j for the integral value (so y j = x j i for some i ∈ [n]), and call y j a boundary item. The j-th knife covers the item y j in some, but not all, of the partial partitions in the Sperner sequence. Now, there are two cases: (a) x j 1 = · · · = x j i = y j − 1 2 and x j i+1 = · · · = x j n = y j for some i ∈ [n], so that y j never occurs in the j-th bundle in the Sperner sequence but sometimes occurs in the (j + 1)-th bundle, or (b) x j 1 = · · · = x j i = y j and x j i+1 = · · · = x j n = y j + 1 2 for some i ∈ [n], so that y j sometimes occurs in the j-th bundle in the Sperner sequence but never occurs in the (j + 1)-th bundle.
Since y j is sometimes covered by a knife, it is not part of any basic bundle. Note that Rounding into a complete partition. We now construct a complete partition of the path P into the bundles (I 1 * , I 2 * , . . . , I n * ) which are defined as follows: Thus, the bundle I j * contains the basic bundle B j , plus all of the boundary items y j−1 or y j that occur in the j-th bundle at some point of the Sperner sequence. Precisely, for each boundary item y j , j ∈ [n − 1], the item y j is placed in bundle I j+1 * in case (a) above, and it is placed in bundle I j * in case (b). Thus, every item is allocated to exactly one bundle.
An EF2 allocation. We first show that the partition (I 1 * , I 2 * , . . . , I n * ) is such that agents' expectations about the value of the bundles I j * are approximately correct (up to two items): This follows by monotonicity of u i , since I j * = I j 1 ∪ · · · ∪ I j n ⊇ I j i ⊇ B j by (5.4). Now, based on the partition, we define an allocation A * by A * (i) = I φ(i) * for each agent i ∈ [n]. Then A * satisfies EF2: For any pair i, j ∈ [n] of agents, we have Hence, we have proved the main result of this section: Theorem 5.4. On a path, for any number of agents with monotone valuation functions, a connected EF2 allocation exists.

EF1 existence for four agents
We have seen that Sperner's lemma can be used to show EF2 existence for any number of agents. Why does our proof in the previous section only establish EF2, and not EF1? The reason is that agents' expectations about the contents of a bundle might differ by up to two goods from what the bundle will actually contain. In the notation of the previous section, an agent i may be presented with a partial partition I i where the j-th bundle I j i is the basic bundle, i.e., I j i = B j . The agent then selects their favorite bundle from I i , implicitly assuming that the j-th bundle in the rounded partition I * will also equal B j , i.e., that I j * = B j . However, it may happen that in fact I j * = {y j−1 } ∪ B j ∪ {y j }, and then i envies the agent who receives bundle j by a margin of two goods.
For four agents, we can adapt our argument to achieve EF1. To do this, we both change the way we round the Sperner sequence into an allocation, and define new labeling functions that better anticipate how a partial partition will be rounded into the final allocation. In this way, agents' expectations about bundles can only be wrong up to one good. In crude terms, agents will expect that each of the two interior bundles will be assigned at least one of the boundary items, and the rounding method ensures that this will indeed happen.
Let n = 4. Formally, to define the labeling function, for each agent i ∈ [n] we construct a virtual valuation functionû i (x, j) which assigns a value to each bundle j ∈ [n] of a partial allocation as specified by a vertex x ∈ V (T half ). The way these virtual valuations are defined differs based on the index j; in particular, end bundles (j = 1, 4) are treated differently from interior bundles (j = 2, 3). The virtual valuations are defined as follows, for each x ∈ V (T half ) and each i ∈ [n], where the middle row (6.2) applies to j = 2 and j = 3: (6.1) Thus, for an interior bundle j = 2, 3, if both the items x j−1 and x j to either side of the bundle are covered by a knife, an agent expects that one of these items (the less-valuable one) will be put into bundle I j * of the final rounded allocation (recall the definition of u − i in equation (2.1)). For exterior bundles, j = 1 (resp. j = 4), if the item x 1 (resp. x 3 ) is not covered by a knife, the agent does not expect the interior item (next to the knife) to belong to the final bundle I j * , even though it belongs to the observed bundle I j i . Otherwise, the virtual allocations are equal to u i (I j (x)), so the agent expects that I j * = I j i . Later, we show that these expectations are correct up to one item.
Using these virtual valuations, we define labeling functionsL i : V (T half ) → [n] so that One can check that these valuation functions are still proper. Again, by Sperner's lemma, there exists an elementary simplex S * = conv(x 1 , x 2 , . . . , x n ) of the triangulation T half which is fully-labeled according to our new labeling function: there is a permutation φ : [n] → [n], withL i (x i ) = φ(i) for all i ∈ [n]. Again, this elementary simplex induces a Sperner sequence (A 1 , . . . , A n ) of partial partitions.
To shorten a case distinction, we assume that y 2 ∈ I 2 1 ∪ I 2 2 ∪ I 2 3 ∪ I 2 4 , i.e., that the boundary item y 2 appears in the second but not in the third bundle in the Sperner sequence. This assumption is without loss of generality, since by the left-right symmetry of the definition of virtual valuations, if necessary we can reverse the path P and consider the same elementary simplex with vertices ordered in reverse (x 4 , x 3 , x 2 , x 1 ); it will still be fully-labeled.
With this assumption made throughout the rest of the argument, we now round the Sperner sequence into a complete partition (I 1 * , I 2 * , I 3 * , I 4 * ) of P defined as follows: Depending on the placement of the boundary item y 1 , we will either have I 1 * = B 1 or I 1 * = B 1 ∪ {y 1 }; and either I 2 With these choices, each interior bundle (j = 2, 3) receives at least one of the boundary items adjacent to it.
The main part of showing that the partition (I 1 * , I 2 * , I 3 * , I 4 * ) can be made into an EF1 allocation is an analogue of (5.5), which shows that agents' expectations about their bundle are approximately correct. The following analogous proposition is proved by case analysis.
-Suppose x 1 i ∈ Z. Then y 1 = x 1 i and B 1 = {1, . . . , . Now, either * y 1 = x 1 i − 1 2 so that y 1 ∈ I 1 i , and so I 1 * = B 1 ∪ {y 1 } = {1, . . . , x 1 i − 1 2 }, or * y 1 = x 1 i + 1 2 so that y 1 ∈ I 1 * , and so I 1 ). First note that I 2 i (x) = B 2 : this is because both y 1 and y 2 appear in the second bundle of the Sperner sequence (by the case and the wlog assumption), so that x 1 i y 1 and y 2 x 2 i . Since at least one of x 1 i or x 2 i is not integral, at least one of y 1 or y 2 must be in -Suppose x 2 i ∈ Z and x 3 i ∈ Z. So x 2 i = y 2 and x 3 i = y 3 . Thenû i (x i , 3) = u − i ({y 2 , . . . , y 3 }). Thus -Otherwise, since y 2 does not appear in I 3 1 (x) (by our wlog assumption), we have that Now again, based on the partition, we can define an allocation A * by A * (i) = I φ(i) * for each agent i ∈ [n]. Thus, each agent i receives the bundle in the complete partition corresponding to i's most-preferred index φ(i). We prove that A * satisfies EF1: For any pair i, j ∈ [n] of agents, we have by Proposition 6.1 ). by Proposition 6.1 Hence, we have proved the main result of this section: Theorem 6.2. On a path, for four agents with monotone valuation functions, a connected EF1 allocation exists.
For five or more agents, we were not able to construct labeling functions and a rounding scheme which ensure that agents' expectations are correct up to one item. In the four-agent case, each interior bundle is adjacent to an exterior bundle (which helps in the construction), but for five agents, there is a middle bundle whose neighboring bundles are also interior.

EF1 existence for identical valuations
A special case of the fair division problem is the case of identical valuations, where all agents have the same valuation for the goods: for all agents i, j ∈ N and every bundle I ∈ C(V ), we have u i (I) = u j (I). We then write u(I) for the common valuation of bundle I. The case of identical valuations often allows for more positive results and an easier analysis. Indeed, we can prove that, for identical valuations and any number of agents, an EF1 allocation connected on a path is guaranteed to exist and can be found in polynomial time. Now, one might guess that in the restricted case of identical valuations, egalitarian allocations are EF1. However, the leximin-optimal connected allocation may fail EF1: Consider a path with five items and additive valuations 1-3-1-1-1 shared by three agents. The unique leximin allocation is (1, 3, 1-1-1), which induces envy even up to one good. The same allocation also uniquely maximizes Nash welfare, so the Nash optimum also does not guarantee EF1. In contrast, when requiring bundles to satisfy matroid constraints (rather than connectivity constraints), the Nash optimum is EF1 with identical valuations (Biswas and Barman, 2018).
Maximizing an egalitarian objective seemed promising because it ensures that no-one is too badly off, and therefore has not much reason to envy others. The problem is that some bundles might be too desirable. To fix this, we could try to reallocate items so that no bundle is too valuable. This is exactly the strategy of our algorithm: It starts with a leximin allocation, and then moves items from high-value bundles to lower-value bundles, until the result is EF1. In more detail, the algorithm identifies one agent i who is worst-off in the leximin allocation, and then adjusts the allocation so that i does not envy any other bundle up to one good. The algorithm does this by going through all bundles in the allocation, outside-in, and if i envies a bundle I j even up to one good, it moves one item from I j inwards (in i's direction), see Figure 7. As we will show, a key invariant preserved by the algorithm is that the value Figure 7.: If i envies j even up to one good, Algorithm 1 takes an item out of bundle I j and moves it in i's direction.
of I i never increases, and i remains worst-off. Thus, since i does not envy others up to one good, the allocation at the end is EF1. Formally, a leximin allocation is an allocation which maximizes the lowest utility of an agent; subject to that it maximizes the second-lowest utility, and so on. In particular, if the highest achievable minimum utility is u L , then the leximin allocation is such that every agent has utility at least u L , and the number of agents with utility exactly u L is minimum.
Algorithm 1. Find a connected EF1 allocation of a path P with identical and monotonic valuations Input: a path P = (v 1 , v 2 , . . . , v m ), and n agents with identical and monotonic valuations u Output: an EF1 connected allocation of P 1: Let A = (I 1 , . . . , I n ) be a leximin allocation of P 2: Fix an agent i with minimum utility in A, i.e., u(I i ) u(I j ) for all j ∈ [n] 3: for j = 1, . . . , i − 1 do 4: if i envies I j even up to one good, i.e., u(I i ) < u − (I j ) then 5: repeatedly delete the rightmost item of I j and add it to I j+1 until u(I i ) u − (I j ) 6: for j = n, . . . , i + 1 do 7: if i envies I j even up to one good, i.e., u(I i ) < u − (I j ) then 8: repeatedly delete the leftmost item of I j and add it to I j−1 until u(I i ) u − (I j ) 9: return A Claim 2. After both for-loops terminate, agent i does not envy any agent up to one good. For any j = i, agent i does not envy j up to one good immediately after the relevant loop has handled j, and at no later stage of the algorithm does I j change.
It follows that the allocation A returned by the algorithm is EF1: By Claim 1, we have i ∈ L(A), so that u(I j ) u(I i ) for all j ∈ [n]. By Claim 2, agent i does not envy any other agent up to one good, so that u(I i ) u − (I k ) for all k ∈ [n]. Hence, for all j, k ∈ [n], we have u(I j ) u − (I k ), that is, no agent envies another agent up to one good.
Algorithm 1 can be implemented to run in polynomial time, because with identical valuations, one can use dynamic programming to find a leximin allocation in time O(m 2 n 2 ), and the remainder of Algorithm 1 takes time O(mn), as each item is moved at most n times. A slight speed-up can be achieved by observing that the proof of Theorem 7.1 only needed that the initial allocation optimizes the egalitarian welfare u L and minimizes the cardinality of the set L of losers. Such an allocation can be found by dynamic programming in time O(m 2 n), and, after some refinements on the implementation of the dynamic programming approach, the running time can be lowered to O(mn) (see Algorithm 2 in the appendix).
The reallocation stage of our algorithm bears some similarity to Suksompong's (2019, Thm. 2) proof that a u max -equitable allocation exists. Oh et al. (2019, Lem. C.2) proved independently, using an inductive argument, that EF1 allocations on a path exist for identical valuations, and can be found in polynomial time. More recently, Misra et al. (2021) presented another algorithm for this task in the context of aiming for connected allocations satisfying equitability up to one good (EQ1).

Concluding remarks
We have studied the existence of EF1 allocations under connectivity constraints imposed by an undirected graph. We have shown that for two, three, or four agents, an EF1 allocation exists if the graph is traceable and if the agents have monotone valuations. For any number of agents, we also proved that traceable graphs guarantee the existence of an EF2 allocation. The latter two results are proved using Sperner's lemma, which has been used many times in economics and game theory to show the existence of equilibria and fair allocations (Scarf, 1982;Su, 1999). Unusually, in our application we were able to use Sperner's lemma in a setting with indivisibilities. We leave as an open question whether EF1 allocations on a path exist for five and more agents.
Our procedures for identical valuations as well as for the cases of two or three agents can be efficiently implemented, so that we can find EF1 allocations in polynomial time. For our results based on Sperner's lemma, it is not clear how to compute EF1 and EF2 allocations efficiently. On the other hand, as is the case with the computation of other structures whose existence follows from Sperner's lemma (such as Nash equilibrium or more broadly PPAD problems), our proof based on Sperner's lemma allows for a "path-following" algorithm through the subdivided simplex. This type of algorithm has been observed to be practically efficient in other contexts (Scarf, 1967), and may also be efficient in our allocation setting on practical instances. Formally, we do not know of a computational complexity result for the problem of finding EF1 or EF2 allocations on a path. For divisible cake-cutting, it is PPAD-complete to find an ε-approximate envy-free allocation (Deng et al., 2012), implying that it is unlikely that there is an algorithm that runs in time polynomial in n and log 1 ε . However, the PPAD-hardness proof of Deng et al. (2012) uses non-monotone valuations, and thus does not easily extend to our setting, where we assume monotone valuations. For general graphs, Deligkas et al. (2021, Thm. 2) recently showed that deciding whether an EF1 allocation exists on a given instance is NP-hard. Their result applies when the underlying graph is a star, and holds even if the n agents have binary additive valuations.
Regarding strategic aspects, existing results from the literature imply that there are no EF1 allocation rules which are strategyproof. 8 Amanatidis et al. (2017a) characterized all strategyproof allocation mechanisms when there are n = 2 agents with additive valuations over indivisible items (with no connectivity constraints). They then proved that no mechanism in their class guarantees EF1 (Amanatidis et al., 2017a, Sec. 4.2) for m 5 items. It follows that there is also no strategyproof EF1 mechanism that respects connectivity constraints. We can also obtain such a result by reduction from divisible cake-cutting. Fix some ε > 0, and suppose we had a mechanism for allocating a path of M items among n agents while being strategyproof and EF1. Then we can use this mechanism as a mechanism for cake-cutting: Given continuous agent valuations over the interval [0, 1], approximate these by additive valuations over the path of M items and run the mechanism on this instance. For sufficiently large M , the resulting mechanism for cake-cutting will be ε-strategyproof (in the sense that a misreport can increase utility by at most ε) and ε-envy-free (in the sense that envy is bounded by ε). However, the literature on cake-cutting contains impossibilities about strategyproofness and envy-freeness when requiring connected pieces (Bei et al., 2017, Theorem 1, Bei et al., 2018, and the proofs also establish impossibility for the ε-versions of these properties for small enough ε. Hence, for large enough M , no strategyproof EF1 mechanism for the indivisible setting can exist. By using the result of Bei et al. (2018), we can obtain an impossibility for n = 2 and even for binary additive valuations where each agent approves an interval of items beginning with the left-most item. Finally, Peters (2019, Chapter 12) gives a simple direct proof that there are no strategyproof EF1 mechanisms, even for n = 2 agents and m = 5 items on a line.
We gave a forbidden minor type characterization of all graphs that guarantee the existence of EF1 allocations for two agents. It is natural to also consider the case of more than two agents. However, there are several difficulties in extending the characterization result beyond two agents. First, one cannot generalize the notion of a bipolar ordering in a meaningful way; indeed, a tripolar ordering, requiring each initial, middle, and last segment to be connected in a given graph, reduces to the notion of a Hamiltonian path because every consecutive pair of such an ordering must be connected. Second, our two-agent characterization heavily depends on having a simple envy-free protocol: the cut-and-choose procedure. Unfortunately, for three agents, the known protocol becomes much more complex (see Section 4), and for four agents, there is no known explicit protocol that constructs an envy-free division. Nevertheless, Igarashi and Zwicker (2021) recently proposed a forbidden minor type conjecture for the continuous variant of our problem. It would be interesting to explore the discrete version of their conjecture.
In the setting without connectivity constraints, it is possible to achieve efficiency and fairness simultaneously: the maximum Nash welfare solution yields an allocation that is both EF1 and Pareto-optimal . In our model, this is unfortunately impossible, since on a path there are instances where there is no connected allocation which is EF1 and Pareto-optimal, and it is NP-hard to decide whether such an allocation exists (Igarashi and Peters, 2019).
In this paper, we have only considered goods, with monotonic valuations. The setting where some or all items are undesirable (so-called chores) is also of interest (Aziz et al., 2019;Bogomolnaia et al., 2016;Meunier and Zerbib, 2019;Segal-Halevi, 2018;Bouveret et al., 2019;Höhne and van Stee, 2021). On a path, a connected allocation satisfying proportionality up to one good (PROP1) always exists (Aziz et al., 2019), but the existence of EF1 or EF2 allocations in this domain is open. For cake-cutting, when agents consider some parts of the cake undesirable, Sperner's lemma does not directly produce a connected envy-free allocation (Segal-Halevi, 2018), but other methods can prove the existence of such allocations in most cases (Segal-Halevi, 2018;Meunier and Zerbib, 2019).

A.1. Maximin share allocations
The maximin share guarantee of an agent i ∈ N is where Π n denotes the space of all partitions of V into n connected bundles. An allocation A is a maximin share (MMS) allocation if u i (A(i)) MMS i for each agent i ∈ N . (Note that the maximum is taken only over connected partitions, so the MMS value could be lower than the standard definition from the model without connectivity constraints.) Bouveret et al. (2017) showed that an MMS allocation exists if the underlying graph G is a tree. On the other hand, MMS allocations need not exist on a cycle (Bouveret et al., 2017;Lonc and Truszczynski, 2020) or on a complete graph (Kurokawa et al., 2018). The computational complexity of determining the existence of MMS allocations under several graph constraints has also been investigated (Greco and Scarcello, 2020).
Since we have seen that EF1 or EF2 allocations are guaranteed to exist on a path, it is natural to ask whether we can additionally require MMS: on a path, does there always exist an allocation that satisfies EF1 and MMS?
First, let us note that not every EF1 allocation is also MMS. For 3-1-1-1-3 and three agents, the MMS value is 3 via the partition (3, 1-1-1, 3), but the EF1 allocation (3-1, 1, 1-3) gives the middle agent a utility of only 1. In fact, one can show that this example is worst possible, for subadditive valuations. Valuations u i are subadditive if, for any bundles I, I , we have u i (I ∪ I ) u i (I) + u i (I ). An allocation satisfies α-MMS for some α > 0 if u i (A(i)) α · MMS i for each agent i ∈ N . As MMS allocations need not exist in general, α-MMS allocations have been widely investigated (Amanatidis et al., 2017b(Amanatidis et al., , 2018Kurokawa et al., 2018).
Proof. Let A be an EF1 allocation, write I j = A(j) for all j ∈ [n], and fix some agent i. For each j ∈ [n] \ {i}, let g j ∈ I j be an item such that u i (I i ) u i (I j \ {g j }). We show that u i (I i ) 1 3 MMS i . Let P = (P 1 , . . . , P n ) be a partition of the items into n bundles such that u i (P j ) MMS i for each j ∈ [n]. Since there are n bundles in P but only n − 1 items g j , there must be some bundle P k such that g j ∈ P k for all j ∈ [n] \ {i}; we show that u i (P k ) 3 · u i (I i ).
Suppose for a contradiction that there are three distinct agents j 1 , j 2 , j 3 ∈ [n]\{i} such that P k ∩I jr = ∅ for r = 1, 2, 3. Since P k and the I jr 's are all intervals of a path, the middle interval must be completely contained in P k , that is, I jr ⊆ P k for some r. Hence g jr ∈ P k , contradicting the choice of P k . So P k intersects at most two bundles from A other than I i . Thus, for some j 1 , j 2 ∈ [n] \ {i}, we have P k ⊆ I j1 ∪ I i ∪ I j2 \ {g j1 , g j2 }, and thus by subadditivity, Hence, we have u i (I i ) 1 3 u i (P k ) 1 3 MMS i , as required. Interestingly, using a similar proof, one can show that the two agents receiving the outer bundles of the path both get at least half of their MMS value. This is also tight; consider 1-1-2-2-1-1 for four agents, and the EF1 allocation (1,1-2,2-1,1).
If we do not restrict valuations to be subadditive, then EF1 does not guarantee α-MMS for any α > 0: Consider a path P = (v 1 , v 2 , v 3 ) of three items, and two agents with identical valuations u defined so that u(I) = 1 if I ⊇ {v 1 , v 2 } or I ⊇ {v 3 }, and u(I) = 0 otherwise. Then the MMS value is 1 via the partition (v 1 -v 2 , v 3 ), but the allocation (v 1 , v 2 -v 3 ) is EF1 and gives the left agent utility 0.
For graphs that are not paths, Proposition A.1 does not hold. For a complete graph (i.e., in the absence of connectivity constraints), EF1 only implies 1/n-MMS Amanatidis et al., 2018).
While we have seen that EF1 on a path does not immediately imply MMS, it does imply MMS in many cases. The following lemma will be useful to show that the allocations produced by our arguments in the main text all satisfy the MMS guarantee.
Then for any agent i, there is some r ∈ [n] such that u i (B r ) MMS i .
Thus, we have P k ⊆ P (y r−1 + 1, y r − 1) = B r so that u i (B r ) u i (P k ) MMS i . Theorem A.3. For a path, the EF1 allocations constructed by any of our methods guarantee MMS.
Proof. Discrete cut-and-choose protocol for two agents. Suppose Alice's lumpy tie is v j . Then, using the definition of lumpy tie, a connected partition witnessing Alice's MMS value is either . At the end of the procedure, Alice receives either L(v j ) ∪ {v j } or R(v j ) ∪ {v j }. For either of these options, there is a bundle in P 1 and a bundle in P 2 which are weakly worse. So Alice receives a bundle that satisfies her MMS value. For Bob, he receives his preferred bundle among L(v j ) or R(v j ). These two bundles are of the shape described in Lemma A.2 with y 1 = v j , so Bob's choice satisfies his MMS value.
Moving-knife protocol for three agents. The allocation returned by the algorithm of Theorem 4.3 guarantees MMS. To see this, first suppose the algorithm terminates in Step 3 or Step 4(a). At that step, the bundles L, M , and R are of the shape described in Lemma A.2 with y 1 = v +1 and y 2 = v r . The agent s left who receives L thinks that L is best among L, M, R (since he shouted), so by Lemma A.2 agent s left receives his MMS value. The proof of Theorem 4.3 shows that no other agent envies s left (even without removing an item), so that every other shouter receives value at least u i (L), meaning that player s receives at least her MMS value (since she shouted, she finds L weakly better than M and R). Finally, agent c does not envy any other agent (even without removing an item), and so automatically receives at least his MMS value. Next, suppose the algorithm terminates in Step 2. As the proof of Theorem 4.3 shows, the agent s left does not envy either of the other players, and hence receives at least his MMS value. Apply Lemma A.2 with y 1 = v and y 2 = v r . It follows that for every agent, one of L \ {v }, M , or R provides at least the MMS value. But we know from the proof that any agent prefers either M or R to L \ {v }, and we know that all agents i = s left receive a bundle weakly preferred to both M and R, so i receives his MMS value. Finally, suppose the algorithm terminates in Step 4 (b). Similarly to the argument for Step 2, apply Lemma A.2 with y 1 = v +1 and y 2 = v r . Then, each player thinks that one of L, M , R provides the MMS value. By the proof of Theorem 4.3, agent s left receives a bundle weakly preferred to each of L, M, R, and agents i = s left prefer either M or R to L, and receive a bundle that is weakly preferred to both M and R, so they also receive their MMS value.
Identical valuations. Algorithm 1 gives each agent a utility of at least u * L . By their definitions, the MMS-value is the same as the optimal egalitarian welfare under identical valuations.
EF2 via Sperner's lemma. For each agent i, by Lemma A.2, there exists a basic bundle whose value is at least MMS i . We showed that the allocation A * is such that agent i weakly prefers the bundle i receives in A * to any basic bundle. Hence, A * is an MMS allocation.
EF1 for four agents via Sperner's lemma. For each vertex x i of the full-labeled simplex S * , invoke Lemma A.2 with y 1 = x 1 i , y 2 = x 2 i , y 3 = x 3 i . By case-analysis one can check thatû i (x i , j) u i (B j ) for each j = 1, 2, 3, 4, where the B j 's are defined like in Lemma A.2. By Proposition 6.1, we have that

A.2. Example of an instance with no EFX allocation
We define EFX as follows.
Definition A.4 (EFX). An allocation A satisfies EFX (Envy-freeness up to any outer good) if the envy is bounded up to the least valuable outer good, i.e., for any pair i, j ∈ N of agents, and for every good u ∈ A(j) such that A(j) \ {u} is connected, we have u i (A(i)) u i (A(j) \ {u}).
Example A.5. Consider the instance 2-3-1-3 for three agents. This instance admits no connected EFX allocation: It is clear that no allocation in which some bundle is empty satisfies EFX. In (2,3,(1)(2)(3), the left agent envies the right agent even after removing the outer good of value 1; in (2, 3-1,3), the left agent envies the middle agent even after removing the outer good of value 1; and in (2-3, 1,3), the middle agent envies the left agent even after removing the outer good of value 3. One can also consider the instance 1-1-3-3 for two agents.
A.3. Example of a non-traceable graph that guarantees EF1 Example A.6. Consider a star with three leaves. We will divide the graph among three agents. Consider the allocation where each agent chooses the most favorite leaf-vertex among the unallocated vertices in order, with the last agent in that order being assigned to the central vertex of the star. The resulting allocation satisfies EF1, since the envy towards agents allocated to a single item can be bounded up to one good, and the first and second agent do not envy the third agent if one removes the central vertex from his bundle.

A.4. Efficient computation of SMMS allocations for identical valuations
In this section, we discuss how to compute the initial allocation that is needed for Algorithm 1 to obtain an EF1 allocation under identical valuations (Theorem 7.1).
Given a path P = (v 1 , v 2 , . . . , v m ), n agents with identical monotonic valuations u, and an allocation A = (I 1 , . . . , I n ), write u L (A) := min j∈N u(I j ) to denote the egalitarian welfare of A, i.e., the minimum valuation in A among all agents, and L(A) := {j ∈ [n] : u(I j ) = u L (A)} for the set of agents who obtain this minimum utility. We refer to the agents in L(A) as the losers.
Definition A.7 (SMMS allocation). An allocation of a path for agents with identical monotonic valuations satisfies strong maximin share (SMMS) if it minimizes the number of losers among all allocations maximizing the egalitarian welfare.
In the following, we provide an efficient dynamic programming algorithm for computing an SMMS allocation. We first present a simple algorithm that runs in time O(m 2 n), and then we refine it to improve the running time to O(mn).

A suboptimal algorithm.
In order to use a dynamic programming approach, we start by deriving a recurrence relation characterizing the SMMS allocations.
Given two partial allocations A, A , we write A A if either u L (A) > u L (A ) holds, or both u L (A) = u L (A ) and |L(A)| |L(A )| hold; furthermore, we write A ∼ A if both A A and A A hold. We observe that an allocation A of path P for n agents is SMMS iff it is "optimal" according to the ordering relation , i.e., iff A A for any allocation A (of path P for n agents).
For any h ∈ [m + 1] and j ∈ [m], let u[h, j] := u(P (v h , v j )) be the utility assigned by u to the path segment from v h to v j . If h > j then we use the convention that P (v h , v j ) = ∅ and u[h, j] = 0. Given i ∈ [n] and j ∈ [m] ∪ {0}, let A[i, j] be an SMMS allocation of the subpath P (v 1 , v j ) for i agents. Also, let Egal[i, j] and L[i, j] denote the egalitarian welfare and the number of losers of the SMMS allocation A [i, j]. Note that our ultimate aim is to find A[n, m].
For any i ∈ [n] \ {1}, j ∈ [m] ∪ {0} and h ∈ [j + 1], let A[i, h, j] be an allocation of the subpath P (v 1 , v j ) for i agents that is optimal according to after constraining the i-th bundle to be equal to the subpath P (v h , v j ); furthermore, let Egal[i, h, j] and L[i, h, j] denote the egalitarian welfare and the number of losers of allocation A [i, h, j]. Observe that we allow h to reach the value j + 1 in order to model the case in which the i-th agent gets an empty bundle. By definition, it holds that Egal[i, h, j is optimal, and we store the resulting values Egal[i, j] and L[i, j] (which will be used in the subsequent rounds). Then we proceed to the next round. Finally, at the end of the last round (n, m), we can recursively reconstruct the optimal allocation A[n, m] by using the indices of type k[i, j] previously stored.
By (A.3), the resulting algorithm returns an SMMS allocation, and its time complexity is O(m 2 n), given by the number of rounds (which is the number of pairs (i, j) which is O(nm)) multiplied by the complexity of each round (checking each value of h which is in O(m)). k t [i, 0] ← 1 for t = 1, 2, 3 {Egal[i, j] and L[i, j] will be computed in such a way to be respectively the egalitarian welfare and the number of losers of an optimal allocation of subpath P (v 1 , v j ) for i agents; each k t [i, j] will be defined as in (A.4), and will be used to compute an index k[i, j] such that A [i, k[i, j], j] is an optimal allocation of subpath P (v 1 , v j ) for i agents.} 6: for i = 2, . . . , n do 7: for j = 1, . . . , m do 8: t * ← the index t maximizing M t , and then, minimizing L t

14:
Egal[i, j] ← M t * , L[i, j] ← L t * , k[i, j] ← k t * [i, j] {t * is computed in such a way that A[i, k t * [i, j], j] is the optimal allocation among those of type A[i, k t [i, j], j], and by Lemma A.9,A[i,k[i,j], j] is an optimal allocation for subpath P (v 1 , v j ) and i agents.} 15: I n ← P (v k [n,m] , v m ) 16: j ← k[n, m] − 1 17: for i = n − 1, . . . , 2, 1 do 18: j ← k[i, j] − 1 20: return A = (I 1 , . . . , I n ) welfare Egal[i, j] and number of losers L[i, j]. Finally, in lines 15-20 we recursively reconstruct the optimal allocation A[n, m] that is returned as output. Now, we show that the time complexity of Algorithm 2 is O(mn). Observe that the body of the nested for-loops in lines 6-14 can be performed in time T (i, j) = c 2 t=1 (k t [i, j] − k t [i, j − 1]), where c is a constant that does not depend on i and j. Indeed, this running time depends on the computation in lines 8-9 of each index k t [i, j] for t = 1, 2, and to compute it we can simply analyze all the indices from k t [i, j − 1] + 1 to k t [i, j] + 1 only. We conclude that the time complexity T of the nested for-loops in lines 6-14 satisfies Since the time complexity of the other parts of the algorithm is clearly O(mn), it follows that Algorithm 2 terminates in O(mn) time.