Agent Work: Homework6
Claude Sonnet 4.6 · COMP 382: Reasoning about Algorithms
COMP 382: Reasoning about Algorithms
Homework 6
Total Points: 100 (Each problem is worth 20 points)
---
Problem 1: True or False [20 points]
Say whether the following claims are true or false. Justify each of your answers with either a proof or a counterexample.
Part (a)
Any flow graph G has a maximum flow that does not include a cycle in which each edge has positive flow.
Part (b)
If all edges in a graph have distinct capacities, there is a unique maximum flow.
Part (c)
If we multiply all edge capacities in a flow network by a positive number λ, then the minimum cut stays unchanged.
Part (d)
If we add a positive number λ to all edge capacities, then the minimum cut stays unchanged.
---
Problem 2: Flow Reduction [20 points]
You are given a flow network with unit-capacity edges: It consists of a directed graph G = (V, E), a source s ∈ V, and a sink t ∈ V; and capacity cₑ = 1 for every e ∈ E. You are also given a parameter k.
The goal is to delete k edges so as to reduce the maximum s-t flow in G by as much as possible. In other words, you should find a set of edges F ⊆ E so that |F| = k and the maximum s-t flow in G' = (V, E \ F) is as small as possible.
Give a polynomial-time algorithm (k cannot occur in the exponent of the complexity term) to solve this problem.
---
Problem 3: Node Capacities [20 points]
In a standard s-t Maximum Flow problem, we assume edges have capacities, and there is no limit on how much flow is allowed to pass through a node. In this problem, we consider the variant of the MaxFlow problem with node capacities.
Let G = (V, E) be a directed graph, with source s ∈ V, sink t ∈ V, and a non-negative node capacity cᵥ for each node. Given a flow f in this graph, the flow through a node v is defined as f^in(v). We say that a flow is feasible if it satisfies the usual flow-conservation constraints and the node-capacity constraints f^in(v) ≤ cᵥ for all nodes.
Give a polynomial-time algorithm to find an s − t maximum flow in such a node-capacitated network.
---
Problem 4: Station Closing [20 points]
Suppose you are in charge of a rail network connecting a large number of towns. Recently, several cases of a contagious disease have been reported in a town A. Your goal is to close down certain railway stations to prevent the disease from spreading to your hometown B. No trains can pass through a closed station.
To minimize expense, you want to close down as few stations as possible. However, you cannot close the station A, as this would expose you to the disease, and you cannot close the station B, because then you couldn't visit your favorite pub.
Describe and analyze an efficient algorithm, based either on max-flow or min-cut, to find the minimum number of stations that must be closed to block all rail travel from A to B.
The rail network is represented by an undirected graph, with a vertex for each station and an edge for each rail connection between two stations. Two special vertices represent the stations in A and B.
---
Problem 5: Exam Scheduling [20 points]
Consider the following problem of scheduling exams at a university. The university offers n different classes. There are r different rooms on campus and t different time slots in which exams can be offered.
You are given two arrays E[1...n] and S[1...r], where:
- E[i] is the number of students enrolled in the i-th class
- S[j] is the number of seats in the j-th room
At most one final exam can be held in each room during each time slot. Class i can hold its final exam in room j only if E[i] < S[j].
Give an efficient max-flow or min-cut based algorithm to assign a room and a time slot to each class (or report correctly that no such assignment is possible).
State and briefly explain the complexity of your algorithm.
# COMP382 Homework 6
## Student Responses
<!-- Write your solutions below. Add sections for each problem as needed. -->
<!-- Use proper mathematical notation where applicable. -->
[Your solutions here]
COMP382 Homework 6
Student Responses
---
Problem 1: True or False
Part (a)
TRUE.
Proof: Let f be any maximum flow in G. If f contains a cycle C = (v₁ → v₂ → ... → vₖ → v₁) in which every edge has positive flow, let ε = min_{e ∈ C} f(e) > 0. Define a new flow f' by:
- f'(e) = f(e) − ε for every edge e in C
- f'(e) = f(e) for every edge not in C
This is a valid flow: capacity constraints hold (we only decreased flow on cycle edges), and flow conservation holds at every vertex because we removed a balanced cycle (each vertex in C has one unit of ε removed from both its incoming and outgoing cycle edges). The total flow value |f'| = |f|, since the cycle contributes zero net flow from s to t.
Note that f' has strictly fewer edges carrying positive flow than f (the edge(s) achieving the minimum are reduced to 0). Since edge flows are bounded below by 0, repeatedly applying this process terminates. The final flow is a maximum flow with no cycle of positive flow.
---
Part (b)
FALSE.
Counterexample: Consider the graph with nodes s, a, b, t and edges:
- s → a: capacity 2
- s → b: capacity 3
- a → t: capacity 4
- b → t: capacity 5
- a → b: capacity 6
All five capacities are distinct. The minimum cut is {s} | {a,b,t} with capacity 2 + 3 = 5, so the maximum flow value is 5. Both s → a and s → b must be saturated.
For any 0 ≤ x ≤ 2, the following is a valid maximum flow of value 5:
- f(s→a) = 2, f(s→b) = 3, f(a→t) = 2−x, f(a→b) = x, f(b→t) = 3+x
Every such flow has value 5. Since x can range over [0, 2], there are infinitely many maximum flows, so the maximum flow is not unique even with distinct capacities.
---
Part (c)
TRUE.
Proof: Let λ > 0. For any s-t cut (S, T), its capacity after multiplying all edges by λ is:
cap_λ(S, T) = Σ_{(u,v) ∈ E, u ∈ S, v ∈ T} λ · c(u,v) = λ · cap(S, T)
Since λ > 0 is a common positive factor, the relative ordering of all cuts by capacity is preserved:
cap(S₁, T₁) ≤ cap(S₂, T₂) ⟺ cap_λ(S₁, T₁) ≤ cap_λ(S₂, T₂)
Therefore the cut(s) achieving the minimum are exactly the same before and after scaling. The minimum cut (as a set of edges forming the partition) is unchanged.
---
Part (d)
FALSE.
Counterexample: Consider the graph with nodes s, a, b, c, d, t and edges:
- s → a: capacity 10
- a → b, a → c, a → d: each capacity 1
- b → t, c → t, d → t: each capacity 1
Key cuts:
- Cut A: {s} | {a,b,c,d,t} — capacity = 10 (single edge s→a)
- Cut B: {s,a} | {b,c,d,t} — capacity = 1+1+1 = 3 (three edges)
Initially, Cut B is the minimum cut with capacity 3 (< 10 = capacity of Cut A).
After adding λ = 4 to every edge capacity:
- Cut A: capacity = 10 + 4 = 14
- Cut B: capacity = (1+4)+(1+4)+(1+4) = 15
Now Cut A (value 14) is smaller than Cut B (value 15), so the minimum cut has changed from Cut B to Cut A. The minimum cut does not stay unchanged.
(In general, adding λ to each edge increases a cut with k crossing edges by kλ, so cuts with more edges are penalized more. A cut that was minimum because its edges were small can become non-minimum once λ is large enough.)
---
Problem 2: Flow Reduction
Goal: Given a unit-capacity flow network G = (V, E) with source s and sink t, find a set F ⊆ E with |F| = k that minimizes the maximum s-t flow in G' = (V, E \ F).
Key Observation: Let c* = max-flow in G = value of the minimum s-t cut in G (by Max-Flow Min-Cut theorem). We claim the minimum achievable max-flow after removing k edges is max(0, c* − k), and it is achieved by removing k edges from the minimum cut.
Lower bound: For any set F with |F| = k, the max-flow in G' satisfies:
max-flow(G') = min-cut(G') = min_{(S,T)} cap_{G'}(S, T)
For any cut (S, T): cap_{G'}(S, T) = cap_G(S, T) − |F ∩ E(S,T)| ≥ cap_G(S, T) − k ≥ c* − k
(The last inequality uses c* ≤ cap_G(S, T) for every cut, since c* is the minimum.) Taking the min over all cuts: max-flow(G') ≥ max(0, c* − k).
Upper bound: By removing k edges from the minimum cut, we achieve max-flow(G') ≤ c* − k (for k ≤ c*) or 0 (for k > c*).
Algorithm: 1. Compute a maximum flow in G using any standard algorithm. Record the flow value c*. 2. Find the corresponding minimum s-t cut (S*, T*) by BFS/DFS from s in the residual graph; S* = vertices reachable from s. 3. Let C = {edges (u,v) ∈ E : u ∈ S*, v ∉ S*} be the set of cut edges. Note |C| = c*. 4. If k ≤ c*: set F = any k edges from C. 5. If k > c*: set F = C ∪ (any k − c* edges from E \ C). 6. Return F.
Correctness: By the argument above, F achieves max-flow max(0, c* − k) in G', which is optimal.
Complexity: For unit-capacity graphs, max flow can be computed in O(E · √V) time (via Hopcroft-Karp-style blocking flows). Finding the min cut via BFS on the residual graph takes O(V + E). The total running time is O(E√V), which is polynomial in |V| and |E| (k does not appear in the exponent).
---
Problem 3: Node Capacities
Problem: Find a maximum s-t flow in a graph where each node v has a capacity cᵥ constraining the total incoming flow f^in(v) ≤ cᵥ.
Algorithm: Node Splitting
Construct a new "edge-capacitated" flow network G' = (V', E') as follows:
1. Node splitting: For each vertex v ∈ V, create two vertices v_in and v_out with a directed edge (v_in → v_out) of capacity cᵥ. 2. Original edges: For each directed edge (u, v) ∈ E, add the edge (u_out → v_in) in E' with capacity ∞ (or any value ≥ sum of all node capacities). 3. Source and sink: The new source is s_out (or equivalently s_in, since s_in → s_out has capacity cₛ which bounds flow through s). Use s_out as source and t_in as sink. (If the problem states s and t have no incoming capacity constraint, set c_s = c_t = ∞.)
Run any standard max-flow algorithm on G' from s_out to t_in. Return the maximum flow value.
Correctness: Each unit of flow passing through a node v in the original graph must traverse the edge v_in → v_out in G'. Since this edge has capacity cᵥ, at most cᵥ units of flow can pass through v. This exactly enforces the node capacity constraint f^in(v) ≤ cᵥ. Flow conservation and capacity constraints on original edges are preserved because the (u_out → v_in) edges have infinite capacity (they do not restrict flow beyond what the node edges already do). A flow in G is feasible if and only if the corresponding flow in G' is feasible.
Complexity:
- G' has |V'| = 2|V| vertices and |E'| = |E| + |V| edges.
- Running Edmonds-Karp on G' takes O(|V| · |E|²) time (with |V|, |E| referring to the original graph).
- This is polynomial in the input size, so the algorithm runs in polynomial time.
---
Problem 4: Station Closing
Problem: Given an undirected graph G = (V, E) (stations = vertices, rail lines = edges), find the minimum number of vertices (other than A and B) to remove so that no path exists from A to B.
This is the minimum vertex cut problem (restricted to internal vertices), which reduces to a max-flow problem via node splitting.
Algorithm:
1. Build G': Apply node splitting to every vertex except A and B: - For each vertex v ∉ {A, B}: create v_in and v_out with edge (v_in → v_out) of capacity 1. - For A: use A as source (or add A_in → A_out with capacity ∞, since A cannot be closed). - For B: similarly, add B_in → B_out with capacity ∞ (B cannot be closed). - For each undirected edge {u, v} ∈ E: add directed edges (u_out → v_in) and (v_out → u_in) with capacity ∞.
2. Run max flow from A_out to B_in in G'.
3. Output: The value of the maximum flow equals the minimum number of stations to close.
Correctness: By the max-flow min-cut theorem, the max flow equals the minimum cut in G'. Any finite-capacity cut must consist entirely of internal node edges (v_in → v_out) of capacity 1, since the edge copies and A/B internal edges have infinite capacity. Each node edge (v_in → v_out) in the cut corresponds to closing station v. A min cut separates A_out from B_in if and only if the corresponding closed stations block all A-to-B paths. Since the original graph is undirected (both directions are included), every path from A to B in G corresponds to a directed path from A_out to B_in in G'.
Complexity: G' has O(|V|) vertices and O(|E| + |V|) edges. Edmonds-Karp on G' runs in O(|V|³) or O(|V| · |E|²) time, which is polynomial.
---
Problem 5: Exam Scheduling
Problem: Assign each of n classes a room and time slot such that:
- Class i is in room j only if E[i] < S[j].
- At most one exam per (room, time slot) pair.
- Every class is assigned.
Algorithm: Max-Flow on a Bipartite Graph
Build a flow network with the following nodes and edges:
- Source s and Sink t.
- Class nodes: One node cᵢ for each class i (1 ≤ i ≤ n).
- Room nodes: One node rⱼ for each room j (1 ≤ j ≤ r).
Edges: 1. s → cᵢ with capacity 1, for each class i. (Each class needs exactly one assignment.) 2. cᵢ → rⱼ with capacity 1, for each (i,j) pair where E[i] < S[j]. (Class i is eligible for room j.) 3. rⱼ → t with capacity t, for each room j. (Room j has t time slots, so it can host at most t exams total.)
Compute the maximum flow from s to t.
Output:
- If max flow = n: a valid assignment exists. For each class i, it is assigned to the room rⱼ for which f(cᵢ → rⱼ) = 1. Time slots are assigned greedily: for each room, number the assigned classes 1, 2, ... and give them time slots 1, 2, ... (at most t per room).
- If max flow < n: no valid assignment exists.
Correctness:
- Each s → cᵢ edge (cap 1) ensures class i is assigned to at most one room.
- Each rⱼ → t edge (cap t) ensures at most t classes are assigned to room j — one per time slot.
- The edge cᵢ → rⱼ exists only when E[i] < S[j], enforcing the size constraint.
- A max flow of n saturates all s → cᵢ edges, meaning every class is assigned. If fewer than n units flow, some class cannot be assigned.
- The time-slot step works: if k ≤ t classes are assigned to the same room, assigning them distinct time slots 1 through k is always feasible.
Complexity:
- |V| = n + r + 2 nodes.
- |E| ≤ n + nr + r edges (at most one edge per (class, room) pair).
- The maximum flow value is at most n.
- Using BFS-based augmenting paths, each augmentation takes O(|E|) = O(nr) time and increases flow by at least 1, so there are at most n augmentations.
- Total time: O(n²r).
- Alternatively, using Hopcroft-Karp-style blocking flows (since this is a unit-supply network): O(nr√n).
Problem 1: True or False
Score: 20/20 points
Assessment:
Part (a): TRUE — 5/5
Approach: The student correctly identifies the answer as TRUE and provides a rigorous proof by construction: given a max flow with a positive-flow cycle, subtract ε (the minimum flow on the cycle) from every cycle edge, then argue the result is still a valid max flow with strictly fewer positive-flow edges. Termination follows from the finite number of edges.
Strengths:
- Carefully defines ε = min flow on cycle edges
- Explicitly verifies both capacity constraints and flow conservation for the modified flow
- Argues termination cleanly (strictly fewer positive-flow edges each iteration)
This is more thorough than the reference solution. Full marks.
---
Part (b): FALSE — 5/5
Approach: The student provides a concrete counterexample with 4 nodes and 5 edges (capacities 2, 3, 4, 5, 6 — all distinct). They parameterize a family of max flows indexed by x ∈ [0, 2], showing infinitely many distinct maximum flows of value 5.
Verification: I verified the counterexample:
- Flow conservation at a: in = 2, out = (2−x) + x = 2 ✓
- Flow conservation at b: in = 3 + x, out = 3 + x ✓
- All capacity constraints satisfied for x ∈ [0, 2] ✓
- All five capacities are distinct ✓
Excellent counterexample, even stronger than the reference. Full marks.
---
Part (c): TRUE — 5/5
Approach: Shows cap_λ(S,T) = λ · cap(S,T), and since λ > 0, the ordering of cuts is preserved. The cut achieving the minimum is unchanged.
Clean, correct proof matching the reference. Full marks.
---
Part (d): FALSE — 5/5
Approach: Provides a clear counterexample: a graph where the min cut has 3 edges of capacity 1 each (total = 3), while another cut has 1 edge of capacity 10 (total = 10). After adding λ = 4, the 3-edge cut becomes 15 while the 1-edge cut becomes 14, reversing which is minimum.
Verification:
- Original: Cut B (3 edges) = 3, Cut A (1 edge) = 10. Min cut = B ✓
- After λ = 4: Cut B = 15, Cut A = 14. Min cut = A ✓
The student also provides excellent intuition: "adding λ penalizes cuts with more crossing edges by kλ." Full marks.
Rubric Breakdown:
- Part (a): 5/5 — Correct answer with rigorous proof
- Part (b): 5/5 — Correct answer with verified counterexample
- Part (c): 5/5 — Correct answer with clean proof
- Part (d): 5/5 — Correct answer with verified counterexample and good intuition
---
Problem 2: Flow Reduction
Score: 20/20 points
Assessment:
Approach: The student identifies that the optimal strategy is to remove k edges from the minimum cut, achieving a residual max flow of max(0, c* − k). They prove optimality with both a lower bound (any removal of k edges leaves flow ≥ c* − k) and an upper bound (achieved by removing from the min cut).
Strengths:
- Clean separation of lower bound and upper bound arguments
- Lower bound proof is rigorous: for any cut (S,T), cap_{G'}(S,T) ≥ cap_G(S,T) − k ≥ c* − k
- Algorithm is clearly stated with all cases (k ≤ c* and k > c*)
- Complexity analysis leverages the unit-capacity structure to give O(E√V), which is actually tighter than the reference's O(VE²)
- Correctly notes that k does not appear in the exponent
Detailed Feedback: This solution matches the reference approach but is presented with greater rigor. The explicit lower/upper bound structure makes the optimality argument crystal clear. The use of O(E√V) for unit-capacity max flow is a nice touch showing deeper knowledge of flow algorithms.
Rubric Breakdown:
- Algorithm description: 5/5 — Clear, complete algorithm
- Correctness proof (lower bound): 5/5 — Rigorous
- Correctness proof (upper bound): 5/5 — Correct
- Complexity analysis: 5/5 — Polynomial, k not in exponent, tighter than reference
---
Problem 3: Node Capacities
Score: 20/20 points
Assessment:
Approach: Standard node-splitting transformation. Each vertex v is replaced by v_in and v_out connected by an edge of capacity c_v. Original edges (u,v) become (u_out → v_in) with capacity ∞. Max flow is computed from s_out to t_in.
Strengths:
- Clear three-step construction (split, redirect, designate source/sink)
- Correctness argument covers both directions: feasible flow in G' ↔ feasible flow in G
- Notes the caveat about source/sink capacity constraints
- Correct complexity analysis: O(|V|·|E|²)
Detailed Feedback: This solution matches the reference solution precisely. The bidirectional correctness argument (flow in G' implies flow in G, and vice versa) is well-articulated. The handling of source and sink nodes is properly noted.
Rubric Breakdown:
- Construction: 8/8 — Complete and correct node-splitting
- Correctness: 7/7 — Both directions of equivalence shown
- Complexity: 5/5 — Correct analysis
---
Problem 4: Station Closing
Score: 20/20 points
Assessment:
Approach: Reduces to minimum vertex cut via node splitting. Internal vertices get capacity-1 internal edges; A and B get capacity-∞ internal edges (cannot be closed). Undirected edges become pairs of directed edges with ∞ capacity. Max flow from A_out to B_in gives the answer.
Strengths:
- Correctly handles all key details: A and B cannot be closed (∞ capacity), undirected→directed conversion, proper source/sink designation
- Correctness argument via max-flow min-cut is well-structured: finite-capacity cut must consist of internal node edges, each corresponding to closing a station
- Explicitly notes that undirected edges are modeled as two directed edges
Detailed Feedback: This matches the reference solution and handles all the subtleties correctly. The argument that any finite min cut must consist entirely of internal node edges (since all other edges have ∞ capacity) is key and is properly stated. The complexity O(|V|³) is reasonable.
Rubric Breakdown:
- Graph construction: 8/8 — Correct node splitting with proper capacities
- Correctness proof: 7/7 — Min cut ↔ min vertex cut established
- Complexity: 5/5 — Polynomial time confirmed
---
Problem 5: Exam Scheduling
Score: 20/20 points
Assessment:
Approach: The student uses a flow network with class nodes and room nodes (but no explicit time nodes), with room→t edges having capacity t. This differs from the reference solution, which includes explicit time nodes.
Correctness of Alternative Approach: The student's approach is correct. The key insight is that the only constraint involving time slots is that each room hosts at most one exam per slot, i.e., at most t exams total. Since there are no cross-room time-slot constraints (e.g., no constraint like "a student can't have two exams at the same time"), the room→t capacity of t correctly enforces the per-room limit. Time slots are then assigned greedily as a post-processing step: if room j is assigned k ≤ t classes, give them distinct time slots 1 through k. This is always feasible.
Strengths:
- Simpler and more efficient graph than the reference (fewer nodes and edges)
- Clearly articulates why greedy time-slot assignment works as post-processing
- Correctness argument is thorough: explains each edge's role in enforcing constraints
- Provides two complexity bounds: O(n²r) with BFS augmenting paths and O(nr√n) with Hopcroft-Karp
- Correctly identifies the max-flow-equals-n condition for feasibility
Detailed Feedback: This is an elegant alternative to the reference solution. The reference models time slots explicitly with O(t) additional nodes and O(rt) additional edges, while the student's approach avoids this overhead entirely. Both are correct — the student's is more efficient. The complexity analysis is more detailed than the reference.
Rubric Breakdown:
- Flow network construction: 8/8 — Correct alternative construction
- Correctness argument: 7/7 — All constraints properly enforced
- Complexity analysis: 5/5 — Two valid bounds provided
---
Overall Summary
| Problem | Score | Notes |
|---|---|---|
| 1 (True/False) | 20/20 | All four parts correct with rigorous justifications |
| 2 (Flow Reduction) | 20/20 | Optimal algorithm with tight complexity analysis |
| 3 (Node Capacities) | 20/20 | Standard node-splitting, complete correctness proof |
| 4 (Station Closing) | 20/20 | Correct reduction to min vertex cut |
| 5 (Exam Scheduling) | 20/20 | Elegant alternative to reference; simpler graph, equally correct |
| Total | 100/100 |
General Comments:
This is an outstanding submission. Every problem is solved correctly with clear, rigorous justifications. Several answers go beyond the reference solution in quality:
- Problem 1(b): The parameterized family of flows is more convincing than a simple two-flow example
- Problem 1(d): Includes excellent intuition about why adding λ penalizes cuts with more edges
- Problem 2: Tighter complexity bound (O(E√V) vs O(VE²)) leveraging unit capacities
- Problem 5: A simpler, more efficient construction that avoids explicit time nodes
The student demonstrates strong command of max-flow/min-cut theory, node-splitting reductions, and algorithm design. Proofs are well-structured with clear forward and backward arguments where needed.
Total: 100/100
diff --git a/writeup.md b/writeup.md
index eda66f5..c48d986 100644
--- a/writeup.md
+++ b/writeup.md
@@ -2,8 +2,200 @@
## Student Responses
-<!-- Write your solutions below. Add sections for each problem as needed. -->
-<!-- Use proper mathematical notation where applicable. -->
+---
-[Your solutions here]
+## Problem 1: True or False
+### Part (a)
+
+**TRUE.**
+
+**Proof:** Let f be any maximum flow in G. If f contains a cycle C = (v₁ → v₂ → ... → vₖ → v₁) in which every edge has positive flow, let ε = min_{e ∈ C} f(e) > 0. Define a new flow f' by:
+- f'(e) = f(e) − ε for every edge e in C
+- f'(e) = f(e) for every edge not in C
+
+This is a valid flow: capacity constraints hold (we only decreased flow on cycle edges), and flow conservation holds at every vertex because we removed a balanced cycle (each vertex in C has one unit of ε removed from both its incoming and outgoing cycle edges). The total flow value |f'| = |f|, since the cycle contributes zero net flow from s to t.
+
+Note that f' has strictly fewer edges carrying positive flow than f (the edge(s) achieving the minimum are reduced to 0). Since edge flows are bounded below by 0, repeatedly applying this process terminates. The final flow is a maximum flow with no cycle of positive flow.
+
+---
+
+### Part (b)
+
+**FALSE.**
+
+**Counterexample:** Consider the graph with nodes s, a, b, t and edges:
+- s → a: capacity 2
+- s → b: capacity 3
+- a → t: capacity 4
+- b → t: capacity 5
+- a → b: capacity 6
+
+All five capacities are distinct. The minimum cut is {s} | {a,b,t} with capacity 2 + 3 = 5, so the maximum flow value is 5. Both s → a and s → b must be saturated.
+
+For any 0 ≤ x ≤ 2, the following is a valid maximum flow of value 5:
+- f(s→a) = 2, f(s→b) = 3, f(a→t) = 2−x, f(a→b) = x, f(b→t) = 3+x
+
+Every such flow has value 5. Since x can range over [0, 2], there are infinitely many maximum flows, so the maximum flow is not unique even with distinct capacities.
+
+---
+
+### Part (c)
+
+**TRUE.**
+
+**Proof:** Let λ > 0. For any s-t cut (S, T), its capacity after multiplying all edges by λ is:
+
+cap_λ(S, T) = Σ_{(u,v) ∈ E, u ∈ S, v ∈ T} λ · c(u,v) = λ · cap(S, T)
+
+Since λ > 0 is a common positive factor, the relative ordering of all cuts by capacity is preserved:
+
+cap(S₁, T₁) ≤ cap(S₂, T₂) ⟺ cap_λ(S₁, T₁) ≤ cap_λ(S₂, T₂)
+
+Therefore the cut(s) achieving the minimum are exactly the same before and after scaling. The minimum cut (as a set of edges forming the partition) is unchanged.
+
+---
+
+### Part (d)
+
+**FALSE.**
+
+**Counterexample:** Consider the graph with nodes s, a, b, c, d, t and edges:
+- s → a: capacity 10
+- a → b, a → c, a → d: each capacity 1
+- b → t, c → t, d → t: each capacity 1
+
+Key cuts:
+- Cut A: {s} | {a,b,c,d,t} — capacity = 10 (single edge s→a)
+- Cut B: {s,a} | {b,c,d,t} — capacity = 1+1+1 = 3 (three edges)
+
+Initially, Cut B is the minimum cut with capacity 3 (< 10 = capacity of Cut A).
+
+After adding λ = 4 to every edge capacity:
+- Cut A: capacity = 10 + 4 = 14
+- Cut B: capacity = (1+4)+(1+4)+(1+4) = 15
+
+Now Cut A (value 14) is smaller than Cut B (value 15), so the minimum cut has **changed** from Cut B to Cut A. The minimum cut does not stay unchanged.
+
+(In general, adding λ to each edge increases a cut with k crossing edges by kλ, so cuts with more edges are penalized more. A cut that was minimum because its edges were small can become non-minimum once λ is large enough.)
+
+---
+
+## Problem 2: Flow Reduction
+
+**Goal:** Given a unit-capacity flow network G = (V, E) with source s and sink t, find a set F ⊆ E with |F| = k that minimizes the maximum s-t flow in G' = (V, E \ F).
+
+**Key Observation:** Let c* = max-flow in G = value of the minimum s-t cut in G (by Max-Flow Min-Cut theorem). We claim the minimum achievable max-flow after removing k edges is max(0, c* − k), and it is achieved by removing k edges from the minimum cut.
+
+**Lower bound:** For any set F with |F| = k, the max-flow in G' satisfies:
+
+max-flow(G') = min-cut(G') = min_{(S,T)} cap_{G'}(S, T)
+
+For any cut (S, T):
+cap_{G'}(S, T) = cap_G(S, T) − |F ∩ E(S,T)| ≥ cap_G(S, T) − k ≥ c* − k
+
+(The last inequality uses c* ≤ cap_G(S, T) for every cut, since c* is the minimum.) Taking the min over all cuts: max-flow(G') ≥ max(0, c* − k).
+
+**Upper bound:** By removing k edges from the minimum cut, we achieve max-flow(G') ≤ c* − k (for k ≤ c*) or 0 (for k > c*).
+
+**Algorithm:**
+1. Compute a maximum flow in G using any standard algorithm. Record the flow value c*.
+2. Find the corresponding minimum s-t cut (S*, T*) by BFS/DFS from s in the residual graph; S* = vertices reachable from s.
+3. Let C = {edges (u,v) ∈ E : u ∈ S*, v ∉ S*} be the set of cut edges. Note |C| = c*.
+4. If k ≤ c*: set F = any k edges from C.
+5. If k > c*: set F = C ∪ (any k − c* edges from E \ C).
+6. Return F.
+
+**Correctness:** By the argument above, F achieves max-flow max(0, c* − k) in G', which is optimal.
+
+**Complexity:** For unit-capacity graphs, max flow can be computed in O(E · √V) time (via Hopcroft-Karp-style blocking flows). Finding the min cut via BFS on the residual graph takes O(V + E). The total running time is **O(E√V)**, which is polynomial in |V| and |E| (k does not appear in the exponent).
+
+---
+
+## Problem 3: Node Capacities
+
+**Problem:** Find a maximum s-t flow in a graph where each node v has a capacity cᵥ constraining the total incoming flow f^in(v) ≤ cᵥ.
+
+**Algorithm: Node Splitting**
+
+Construct a new "edge-capacitated" flow network G' = (V', E') as follows:
+
+1. **Node splitting:** For each vertex v ∈ V, create two vertices v_in and v_out with a directed edge (v_in → v_out) of capacity cᵥ.
+2. **Original edges:** For each directed edge (u, v) ∈ E, add the edge (u_out → v_in) in E' with capacity ∞ (or any value ≥ sum of all node capacities).
+3. **Source and sink:** The new source is s_out (or equivalently s_in, since s_in → s_out has capacity cₛ which bounds flow through s). Use s_out as source and t_in as sink. (If the problem states s and t have no incoming capacity constraint, set c_s = c_t = ∞.)
+
+Run any standard max-flow algorithm on G' from s_out to t_in. Return the maximum flow value.
+
+**Correctness:** Each unit of flow passing through a node v in the original graph must traverse the edge v_in → v_out in G'. Since this edge has capacity cᵥ, at most cᵥ units of flow can pass through v. This exactly enforces the node capacity constraint f^in(v) ≤ cᵥ. Flow conservation and capacity constraints on original edges are preserved because the (u_out → v_in) edges have infinite capacity (they do not restrict flow beyond what the node edges already do). A flow in G is feasible if and only if the corresponding flow in G' is feasible.
+
+**Complexity:**
+- G' has |V'| = 2|V| vertices and |E'| = |E| + |V| edges.
+- Running Edmonds-Karp on G' takes O(|V| · |E|²) time (with |V|, |E| referring to the original graph).
+- This is polynomial in the input size, so the algorithm runs in **polynomial time**.
+
+---
+
+## Problem 4: Station Closing
+
+**Problem:** Given an undirected graph G = (V, E) (stations = vertices, rail lines = edges), find the minimum number of vertices (other than A and B) to remove so that no path exists from A to B.
+
+This is the **minimum vertex cut** problem (restricted to internal vertices), which reduces to a max-flow problem via node splitting.
+
+**Algorithm:**
+
+1. **Build G':** Apply node splitting to every vertex except A and B:
+ - For each vertex v ∉ {A, B}: create v_in and v_out with edge (v_in → v_out) of capacity 1.
+ - For A: use A as source (or add A_in → A_out with capacity ∞, since A cannot be closed).
+ - For B: similarly, add B_in → B_out with capacity ∞ (B cannot be closed).
+ - For each undirected edge {u, v} ∈ E: add directed edges (u_out → v_in) and (v_out → u_in) with capacity ∞.
+
+2. **Run max flow** from A_out to B_in in G'.
+
+3. **Output:** The value of the maximum flow equals the minimum number of stations to close.
+
+**Correctness:** By the max-flow min-cut theorem, the max flow equals the minimum cut in G'. Any finite-capacity cut must consist entirely of internal node edges (v_in → v_out) of capacity 1, since the edge copies and A/B internal edges have infinite capacity. Each node edge (v_in → v_out) in the cut corresponds to closing station v. A min cut separates A_out from B_in if and only if the corresponding closed stations block all A-to-B paths. Since the original graph is undirected (both directions are included), every path from A to B in G corresponds to a directed path from A_out to B_in in G'.
+
+**Complexity:** G' has O(|V|) vertices and O(|E| + |V|) edges. Edmonds-Karp on G' runs in **O(|V|³)** or O(|V| · |E|²) time, which is polynomial.
+
+---
+
+## Problem 5: Exam Scheduling
+
+**Problem:** Assign each of n classes a room and time slot such that:
+- Class i is in room j only if E[i] < S[j].
+- At most one exam per (room, time slot) pair.
+- Every class is assigned.
+
+**Algorithm: Max-Flow on a Bipartite Graph**
+
+Build a flow network with the following nodes and edges:
+
+- **Source** s and **Sink** t.
+- **Class nodes:** One node cᵢ for each class i (1 ≤ i ≤ n).
+- **Room nodes:** One node rⱼ for each room j (1 ≤ j ≤ r).
+
+Edges:
+1. s → cᵢ with capacity 1, for each class i. (Each class needs exactly one assignment.)
+2. cᵢ → rⱼ with capacity 1, for each (i,j) pair where E[i] < S[j]. (Class i is eligible for room j.)
+3. rⱼ → t with capacity t, for each room j. (Room j has t time slots, so it can host at most t exams total.)
+
+Compute the maximum flow from s to t.
+
+**Output:**
+- If max flow = n: a valid assignment exists. For each class i, it is assigned to the room rⱼ for which f(cᵢ → rⱼ) = 1. Time slots are assigned greedily: for each room, number the assigned classes 1, 2, ... and give them time slots 1, 2, ... (at most t per room).
+- If max flow < n: no valid assignment exists.
+
+**Correctness:**
+- Each s → cᵢ edge (cap 1) ensures class i is assigned to at most one room.
+- Each rⱼ → t edge (cap t) ensures at most t classes are assigned to room j — one per time slot.
+- The edge cᵢ → rⱼ exists only when E[i] < S[j], enforcing the size constraint.
+- A max flow of n saturates all s → cᵢ edges, meaning every class is assigned. If fewer than n units flow, some class cannot be assigned.
+- The time-slot step works: if k ≤ t classes are assigned to the same room, assigning them distinct time slots 1 through k is always feasible.
+
+**Complexity:**
+- |V| = n + r + 2 nodes.
+- |E| ≤ n + nr + r edges (at most one edge per (class, room) pair).
+- The maximum flow value is at most n.
+- Using BFS-based augmenting paths, each augmentation takes O(|E|) = O(nr) time and increases flow by at least 1, so there are at most n augmentations.
+- **Total time: O(n²r).**
+- Alternatively, using Hopcroft-Karp-style blocking flows (since this is a unit-supply network): **O(nr√n)**.
Sub-Model Usage
| Model | Input | Output | Cache Read | Cost |
|---|---|---|---|---|
| claude-sonnet-4-6 | 4 | 4.4K | 94.5K | $0.36 |
BSCS Bench