Professional Documents
Culture Documents
Ex 1
Ex 1
Question 1
Let G be a circular directed weighted graph with n nodes (n being the amount
of gas stations), s.t. the sum of all weights is exactly 0.
We can correspond each gas station to a node such that:
• each two nodes are neighbours i their matching gas stations are neigh-
bours
• the weight of a node is the distance which could be travelled with the gas
in the station less the length of the road to the next station
X
∃e ∈ G s.t. ∀e0 ∈ G : w (e? ) ≥ 0
e? ∈[e,e0 ]
where w is the weight function and [e, e0 ] is the (unanimously dened) simple
0
line between e and e.
Let us assume that no such e exists, thus that
X
∀e ∈ G : ∃e0 ∈ G s.t w (e? ) < 0
e? ∈[e,e0 ]
For the simplicity of the proof well say that e is negatively distant from e0 .
Let e0 ∈ G be any node, according to our assumption there is an e1 which is
negatively distant from e0 , and an e2 which is negatively distant from e1 and
so on.
Let us create a succession of n+1 such nodes, since there are only n gas stations,
we know that ∃i, j s.t. i 6= j and ei = ej .
1
Thus the succession (ei , ..., ej ) starts and ends at the same place, and let us
assume it goes over the entire circle k times, thus, the total weight traversed
along this succession is
X
k w(e)
e∈G
X X X X
k w(e) = w (e? ) + ... + w (e? ) < 0 =⇒ w(e) < 0
e∈G e? ∈[ei ,ei+1 ] e? ∈[ej−1 ,ej ] e∈G
Question 2
I suggest this algorithm (which I like to call a reverse Kruskal):
Correctness proof :
First we must prove that RK indeed returns a tree. The constraints promise
that the output graph is simply connected.
Let us assume that the output contains a circle, and let us denote vj as the
heaviest edge in the circle. Since vj is the rst edge traversed by RK, it's still
containt in a circle, which means removing it will not divide the graph into
two connectivity components, thus having the algorithm remove it, which is a
contradiction.
This proves the output is indeed a spanning tree, let us prove that it has a
minimal maximal edge.
The correctness is trivial in case removing a1 (or any ai s.t. w(ai ) = w(a1 ))
divides the graph into two connectivity components, as a1 (or one of it's dopel-
gangers) must stay thus making any spanning tree a solution.
Assuming that is not the case, let us denote a solution as the ordered set of
edges removed from the graph, and denote the output of our algorithm as RK .
Let B be the set of optimal solutions and let S ∈ B , there is a maximal j s.t.
∀j ≤ i : vj ∈ S , assuming that RK is not optimal means that there exists a
minimal j ≤ i s.t. vj ∈
/ RK .
2
But since S is a solution we know that after removing v1 , ..., vj−1 from G, we get
a connected graph, and furthermore, since vj ∈ S we know that G − {v1 , ..., vj }
is still connected.
Hence, after removing the edges {v1 , ..., vj−1 } RK would remove vj , proving
that vj ∈ RK , in contradiction.
Question 3
Let us consider a spanning tree of G, and let v∈G be a leaf in that tree.
Thus, removing v and all if it's edges, doesn't harm the connectivity of the
graph.
Question 4
• Go over each of the numbers in the array from x1 to xn , if the current
number isn't contained in any segment add it to the output set.
Proof of correctness:
Since the algorithm will add any number not yet covered it's obvious that the
output covers all numbers in the array.
But from the denition of our algorithm we get that xi = cj+1 thus [xi , yj+1 +
1] ⊆ [xi , cj+1 + 1] (as the length of the rightmost segment is 1, which is the
maximal length, and they both have the same starting point).
3
This proves that {y1 , ..., yj+1 , cj+2 , ..., cm } as also a solution, in contradiction
with j being maximal.