Editorial for Baltic OI '13 P3 - Pipes


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Task

A connected, simple, graph on n vertices and m edges is given. Weights are assigned to all edges (they are integers but need not be positive). These weights are not known but for each vertex the sum of weights of the edges incident to it is given. Can the weights be determined uniquely? If yes, what are they?

Intended Solution

We will use graph theoretic terminology, seeing reservoirs as vertices and pipes as edges of a graph G. For each edge e, let we be its weight. We allow we to take integer values, with the following interpretation:

  • if we0 then 2we m3/s of water is pumped into e,
  • if we0 then 2we m3/s of water is drained from e.

For each vertex v, we know

sv=eΓ(v)we(1)

which is the sum of weights of the edges incident to v (Γ(v) is the set of such edges). Note that (1) gives n linear equations for m unknowns we. There can be a unique solution only if mn (this is true even for integer values of we) (). Moreover, as G is connected, mn1.

Suppose m=n1. Then G is a tree and has a leaf (a vertex of degree one, that is, with exactly one incident edge). Pick a leaf v and let u be the vertex to which v is joined by an edge. Then (1) gives wuv=sv which is known. Remove v together with the edge uv from G and subtract wuv from su. The remaining graph is again a tree. Continue this process until a single vertex remains. Then G has a unique solution which we have found.

Now suppose m=n. Remove leaves as before, until there are no more leaves. What remains is a connected graph on n=nl vertices and m=nl edges where l is the number of leaves removed. This is a cycle of length n. If n is even then there are multiple solutions (see Fig. 1).

Figure 1: Cycles of even length have multiple solutions: given one solution, add one to black edges and subtract one from white edges to get another.

If n is odd, however, we have a unique solution. Indeed, suppose 1,2,,n1 are the vertices in this order. From (1) we have

wn1=s1w12=s1s2+w23=s1s2+s3w34=s1s2+s3+snwn1

so

wn1=s1s2+s3+sn2

This determines wn1 uniquely and having its value we can easily fill in the remaining weights: w12=s1wn1, w23=s2w12 and so on.

If m>n, we know from earlier considerations that there is more than one possible solution.

Given a connected graph G on n vertices, we can do this in total time O(n): find the initial leaves of G and put them in a stack. Consider the top leaf: remove it and decrease the degree of its neighbour. Check if this degree is one: if yes, add the neighbour to the stack. Do this until no leaves remain. So the total time complexity is O(n).

Remark

Observation () can be made purely by combinatorial considerations without using any linear algebra. If G is connected on n vertices and at least n+1 edges then it contains at least two cycles. If one of them has even length, there cannot be a unique solution (Fig. 1). Assume they both have odd length. There are two cases.

  • The cycles have at most one vertex in common. As G is connected, there is a path p that joins the cycles (we allow p to be a single vertex). In Fig. 2, on the left is the case when p has even length (that is, p has an even number of edges) and on the right is the case when p has odd length. In both cases, there is more than one solution.

Figure 2: Perturb weights to get a new solution.
  • The cycles share at least two vertices. Let x be one of the common vertices. Start at x and follow one of the cycles until it intersects the other cycle. Let this intersection point be y. There are three paths joining x and y, any pair of which intersect only at endpoints (see Fig. 3. Let l1, l2 and l3 be their lengths. Pairs of these paths form cycles of lengths l1+l2, l2+l3 and l3+l1. At least one of these numbers is even so there is a path of even length. Referring back to Fig. 1, we know there cannot be a unique solution.

Figure 3: Three pairwise disjoint paths join x to y. We must have an even cycle.

Comments

There are no comments at the moment.