\documentclass[11pt]{article}
\usepackage{amsmath,amssymb,amsthm,graphicx}
\usepackage{fullpage}
\usepackage[capitalise,nameinlink]{cleveref}
\crefname{lemma}{Lemma}{Lemmas}
\crefname{fact}{Fact}{Facts}
\crefname{theorem}{Theorem}{Theorems}
\crefname{corollary}{Corollary}{Corollaries}
\crefname{claim}{Claim}{Claims}
\crefname{example}{Example}{Examples}
\crefname{problem}{Problem}{Problems}
\crefname{setting}{Setting}{Settings}
\crefname{definition}{Definition}{Definitions}
\crefname{assumption}{Assumption}{Assumptions}
\crefname{subsection}{Subsection}{Subsections}
\crefname{section}{Section}{Sections}

\DeclareMathOperator*{\E}{\mathbb{E}}
\let\Pr\relax
\DeclareMathOperator*{\Pr}{\mathbb{P}}

\newcommand{\eps}{\varepsilon}
\newcommand{\inprod}[1]{\left\langle #1 \right\rangle}
\newcommand{\R}{\mathbb{R}}

\newcommand{\handout}[5]{
  \noindent
  \begin{center}
  \framebox{
    \vbox{
      \hbox to 5.78in { {\bf CS 270: Combinatorial Algorithms and Data Structures
        } \hfill #2 }
      \vspace{4mm}
      \hbox to 5.78in { {\Large \hfill #5  \hfill} }
      \vspace{2mm}
      \hbox to 5.78in { {\em #3 \hfill #4} }
    }
  }
  \end{center}
  \vspace*{4mm}
}

\newcommand{\lecture}[4]{\handout{#1}{#2}{#3}{Scribe: #4}{Lecture #1}}

\newtheorem{theorem}{Theorem}[section]
\newtheorem*{theorem*}{Theorem}
\newtheorem{itheorem}{Theorem}

\newtheorem{subclaim}{Claim}[theorem]
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem*{proposition*}{Proposition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem*{lemma*}{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem*{conjecture*}{Conjecture}
\newtheorem{fact}[theorem]{Fact}
\newtheorem*{fact*}{Fact}
\newtheorem{exercise}[theorem]{Exercise}
\newtheorem*{exercise*}{Exercise}
\newtheorem{hypothesis}[theorem]{Hypothesis}
\newtheorem*{hypothesis*}{Hypothesis}
\newtheorem{conjecture}[theorem]{Conjecture}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{setting}[theorem]{Setting}
\newtheorem{construction}[theorem]{Construction}
\newtheorem{example}[theorem]{Example}
\newtheorem{question}[theorem]{Question}
\newtheorem{openquestion}[theorem]{Open Question}
\newtheorem{algorithm}[theorem]{Algorithm}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{protocol}[theorem]{Protocol}
\newtheorem{assumption}[theorem]{Assumption}
\newtheorem{exercise-easy}[theorem]{Exercise}
\newtheorem{exercise-med}[theorem]{Exercise}
\newtheorem{exercise-hard}[theorem]{Exercise$^\star$}
\newtheorem{claim}[theorem]{Claim}
\newtheorem*{claim*}{Claim}

\newtheorem{remark}[theorem]{Remark}
\newtheorem*{remark*}{Remark}
\newtheorem{observation}[theorem]{Observation}
\newtheorem*{observation*}{Observation}

% 1-inch margins, from fullpage.sty by H.Partl, Version 2, Dec. 15, 1988.
% \topmargin 0pt
% \advance \topmargin by -\headheight
% \advance \topmargin by -\headsep
% \textheight 8.9in
% \oddsidemargin 0pt
% \evensidemargin \oddsidemargin
% \marginparwidth 0.5in
% \textwidth 6.5in

% \parindent 0in
% \parskip 1.5ex

\begin{document}

\lecture{2 --- January 19, 2023}{Spring 2023}{Prof.\ Jelani Nelson}{Andrew Lin, Sanjay Gollapudi}

\section{Single-Source Shortest Paths}
We continue our discussion of the Bernstein-Nanongkai-WulffNilsen \cite{BNW22} algorithm for single-source shortest paths with negative edge weights from last lecture. In today's lecture, we describe three of the subroutines of the BNW algorithm. We begin with some definitions:

\begin{definition}
\[w^B(e)= \begin{cases} 
            w(e), & w(e) \geq 0. \\
            w(e) + B, & w(e) < 0.
\end{cases}\]
\end{definition}
\begin{definition}
    For vertex $v,$ $\eta(v)$ is the minimum number of negative edges of all shortest paths from source $s$ to $v$. $P_{G^B}(v)$ denotes the path achieving the value of $\eta(v).$
\end{definition}
\noindent Recall our subroutines: \begin{enumerate}
    \item LowDiamDecomp($G,D$), which we abbreviate as LDD($G,D$). This subroutine assumes that for all edges $e, w(e) \geq 0$ and returns a subset of edges $E'$ such that \begin{itemize}
        \item each $SCC$ in $G\backslash E'$ has a weak diameter $\leq D$
        \item For all edges  $e$, $\Pr(e \in E') \leq O(\frac{w(e)\log^2n}{D}+n^{-10})$
    \end{itemize}
    \item ElimNeg($G$), which finds a good $\phi$ in time $O((\log n) (\Sigma_v[1+\eta_G(v)])).$
    \item FixDAGEdges($G$, $\{V_i\}_i)$ which assumes edges inside each $V_i$ are non-negative and the graph between the $V_i$'s is a DAG. This finds a $\phi$ making edges between any two $V_i$'s non-negative.
    \item ScaleDown($G,\Delta,B)$, which assumes $\eta(G^B) \leq \Delta$. Given a graph with $w(e) \geq -2B$ for all edges $e$, this subroutine returns $\phi$ such that $w_\phi(e) \geq -B$ for all edges $e$.
\end{enumerate}
\subsection{ScaleDown subroutine}
\noindent We use LowDiamDecomp, ElimNeg, and FixDAGEdges to create the ScaleDown subroutine.
\begin{algorithm}
    ScaleDown($G, \delta, B$):
    \begin{enumerate}
        \item if $\Delta \leq 2$ set $\phi_2 \leftarrow 0$, go to Phase 3
        \item $d\leftarrow  \frac{\Delta}{2}$
        \item For all $e\in E, w_{\geq 0}^B \leftarrow\max\{0, w^B(e)\}$
        \item \textbf{Phase 0}
        \item $E' \leftarrow LDD(G_{\geq 0}^B, dB)$ 
        \item \textbf{Phase 1}
        \item $H \leftarrow \bigcup_iG[V_i]$, where $V_i's$ are SCCs of $G\backslash E'$
        \item $\phi_1 \leftarrow \text{ScaleDown}(H, \frac{\Delta}{2}, B)$ 
        \item \textbf{Phase 2}
        \item $\psi \leftarrow \text{FixDAGEdges}(G_{\phi_1}^B\backslash E')$
        \item $\phi_2 \leftarrow \phi_1 +\psi$ 
        \item \textbf{Phase 3}
        \item $\psi' \leftarrow \text{ElimNeg}(G_{\phi_2}^B)$
        \item return $\phi_2 +\psi'$
    \end{enumerate}
    
\end{algorithm}
\begin{figure}[h!]
\centering
\includegraphics[scale=1.3]{3Capture.PNG}
    \caption{Example graph $G$.}
\label{fig:Drawing1}
\end{figure}

The idea here is that after blowing up all edge weights by a factor of $B=2n$, we can repeatedly call ScaleDown $\log B$ times to ensure all weights are at least $-1,$ and then we add $1$ to each edge to make all edges positive. Since each path has length at most $n$ and all edge weights are integers, any two vertices on the scaled-up graph with nonequal distance differ by at least $2n,$ but adding $1$ to each vertex can only increase the distance between two vertices by at most $n.$ Therefore we preserve the ordering of any two paths, so we can run Dijkstra on the graph with the resulting edge weights.

ScaleDown runs in $\Tilde{O}(m\log\Delta)$ time. It consists of 4 phases, where we generate a set $E'$ and repeatedly "fix" edges by making their weights at least $-B,$ thus ensuring $w^B(e)\geq 0$ for all edges $e.$
\begin{enumerate}
    \item $\textbf{Phase 0}$ calls LowDiamDecomp on the graph. LowDiamDecomp generates a set $E'$ of vertices, and guarantees that for any vertex $v$, the expected number of negative edges in a shortest path to $v$ with the fewest number of negative edges contains at small ($O(\log^2 n))$ number of vertices in $E'.$ 
    \item $\textbf{Phase 1}$ fixes all edges within a SCC in $G\backslash E'$ (the black edges in Figure 1). The recursive call to the algorithm requires that $\eta(H^B) \leq \frac{\Delta}{2}$.
    \item $\textbf{Phase 2}$ fixes all edges that connect two SCCs (the yellow edges in Figure 1).
    \item $\textbf{Phase 3}$ fixes all edges in $E'$ (the pink edges in Figure 1). Since shortest paths contain only a small number of these edges, this step is efficient.
\end{enumerate}

\subsection{FixDAGEdges subroutine}
Now we will describe the FixDAGEdges subroutine. The requirement that edges within each of the SCCs $\{V_i\}$ is nonnegative is satisfied due to recursively calling ScaleDown on the graph of SCCs with parameter $B$ returning a $\phi$ with $w_\phi(e)\geq -B,$ for all edges $e$, so when we consider $w_\phi^B,$ all weights will be positive.
\begin{algorithm}
    FixDAGEdges:

    First set $\phi(x)=0$ for all vertices $x$ in the source SCC. For a child SCC, note that for all vertices $u,$ $w_\phi(v,u)=w(v,u)+\phi(u)-\phi(v)$ where $(v,u)$ is an edge from $v$ in the parent SCC. We want $w_\phi(v,u)\geq 0,$ which is equivalent to $\phi(u)\leq w(v,u)+\phi(v).$ We find the maximum $t$ such that $t\leq w(v,z)+\phi(z)$ for all $z$ in the child SCC, and set $\phi(z)=t$ for all such $z.$ Thus all edges between the parent and child have positive weight.
\begin{figure}[h!]
\centering
\includegraphics[scale=1.3]{2Capture.PNG}
    \caption{Example graph $G_{\phi_1}^B$. FixDAGEdges picks prices making all yellow edges nonnegative.}
\label{fig:Drawing2}
\end{figure}

    We simply traverse the SCCs in topological order to assign a valid price to each vertex using the above process, so this can be done in $O(m+n)$ time.
\end{algorithm}

\subsection{ElimNeg subroutine}
Now we will present a weaker version of the the ElimNeg subroutine, which runs in $O((m+n)\eta(G)\log n)$ time. This algorithm uses dynamic programming.
\begin{algorithm}
    
    ElimNeg($G$): 
    \begin{itemize}
        \item $h(v,k) :=$ shortest path length to $v$ using $\leq k$ negative edges such that the last edge is negative
        \item $g(v,k) :=$ shortest path length to $v$ using $\leq k$ negative edges
            \end{itemize}

Recursively, we compute $h$ and $g$ as follows:
        \[h(v,k)= \begin{cases} 
            \infty, & k = 0 \\
            \min\{h(v,k-1), \min_{u, (u,v)\in E, w((u,v))<0}\{g(u,k-1) + w(u,v)\}\} & \text{otherwise}.\\
\end{cases}\]
        \item \[g(v,k) =\begin{cases}    d^+(s,v), & k = 0 \\\min\{g(v,k-1), \min_{u\in V}\{h(u,k)+d^+(u,v)\}\} &\text{otherwise}\end{cases}\]
\end{algorithm}
We use dynamic programming to compute $g(v,k)$ for $k=\eta(G).$

\noindent To show the runtime of this algorithm, first note that $d^+(s,v)$ can be computed using Dijkstra in $O(m+n)$ time. Calculating $g$ from $h$ is more complicated: rather than calculating all values of $h$ directly and minimizing over them, which takes $O(mn)$ time, we instead calculate $h(u,k)+d^+(u,v)$.

To do so, at each step, we create a dummy vertex $\alpha,$ and for all $1\leq i\leq n,$ we add edge $(\alpha, v_i)$ with weight $h(v_i,k)$. Remove all negative edges in the rest of the graph. Note that $h(u,k)+d^+(u,v)$ is the shortest path from $\alpha$ to $v$ with at most $k$ negative edges that passes through $v$, so $\min_{u\in V}\{h(u,k)+d^+(u,v)\}$ is the shortest path from $\alpha$ to $v.$
\begin{figure}[h!]
\centering
\includegraphics[scale=1.6]{1Capture.PNG}
    \caption{The graph created to compute $h(u,k)+d^+(u,v)$.}
\label{fig:Drawing3}
\end{figure}


We use the following result without proof:
\begin{claim}
    Dijkstra can compute the shortest paths from $\alpha$ to all vertices $v$ even if some of the edge weights out of $\alpha$ are negative.
\end{claim}
Therefore we can compute the values of $g(v,k)$ given values of $g$ and $h$ for $k-1$ in $O((m+n)\log n)$ time. Since we want to calculate $g(v,\eta(G)),$ we need to run this $\eta(G)$ times, so this subroutine takes $O((m+n)\eta(G)\log n)$ in total.

\subsection{Remaining details from ScaleDown}
\noindent Now we will prove the claim from \textbf{Phase 0} in ScaleDown.
\begin{claim}
For all vertices $ v, \mathbb{E}|P_{G^B}(v)\cap E'| = O(\log^2n)$
\end{claim}
\begin{proof}
Note that since we add at most $B$ to each negative edge, we have
    \[w_{\geq 0}^B(P_{g^B}(v))\leq w^B(P_{G^B}(v))+ B\cdot|P_{G^B}(v)\cap E^\text{neg}|.\]
    By the existence of our dummy node $s$, $w^B(P_{G^B}(v)) \leq 0$ and we know $|P_{G^B}(v)\cap E^\text{neg}| \leq \eta_{G^B}(v)$. Therefore, $w_{\geq 0}^B(P_{g^B}(v)) \leq \eta_{G^B}(v)\cdot B$. From this we use the fact that LDD guarantees $\Pr(e \in E') \leq O(\frac{w(e)\log^2n}{D}+n^{-10})$ to get
    \begin{align}
        \mathbb{E}|P_{G^B}(v) \cap E'| & = \mathbb{E}\left|\sum_{e \in P_{G^B}(v)}\textbf{1}\{e\in E'\}\right| \\
        &= \sum_{e\in E}\mathbb{P}(e\in E')\\
        &\leq O(\frac{w_{\geq 0}^B(P_{G^B}(v))\log^2n}{D} + n^{-9}) \\
        &= O(\frac{\eta_{G^B}(v)B\log^2n}{D} + n^{-9})\\
        &= O(\frac{\Delta B\log^2n}{dB} + n^{-9})\\
        &= O(\frac{\Delta \log^2n}{\frac{\Delta}{2}} + n^{-9})\\
        &= O(2\log^2n + n^{-9})\\
        &= O(\log^2n)
    \end{align}
    
\end{proof}

\begin{claim}
    If $G$ contains no negative cycles, then $\eta(H^B)\leq\frac{\Delta}{2}$.
  \end{claim}
  \begin{proof}
    Take an arbitrary vertex $v$ and look at the path $P_{H^B}(v)$ from $s$ to $v$. Let $u$ be the vertex on $P_{H^B}(v)$ immediately after $s$ (which may equal $v$), and let $P$ be subpath from $u$ onward to $v$ (simply remove $s$ and the edge $(s,u)$). Then
    \begin{align}
\nonumber      \mathop{dist}_G(u,v) &\le w_H(P)\\
\nonumber      {}&\le w_{H^B}(P) - |E^{\mathop{neg}}(H^B)\cap P|\cdot B\\
      {}&= w_{H^B}(P) - \eta_{H^B}(v)\cdot B \label{eqn:eq1}\\      
      {}&\le - \eta_{H^B}(v)\cdot B \label{eqn:eq2}
    \end{align}
    where \cref{eqn:eq1} uses that $w(s,u) = 0$, and \cref{eqn:eq2} uses that there is a path from $s$ to $v$ of length $0$ (namely the single edge) and thus the shortest path can be no longer.

    Now, by guarantees of LowDiamDecomp on weak diameter, we know $\mathop{dist}_G(v,u) \le dB = \Delta B/2$. Since $G$ contains no negative cycles, combining this with $\mathop{dist}_G(u,v) \le -\eta_{H^B}(v)\cdot B$ then implies $\Delta B / 2 - \eta_{H^B}(v)\cdot B \ge 0$. Rearranging gives $\eta_{H^B}(v) \le \Delta /2$. The claim holds since $v$ was arbitrary.
    \end{proof}

\section{Max Flow}
We now consider the MaxFlow problem.
\subsection{Basics}
We are given the following:
\begin{itemize}
    \item A capacitated graph $G = (V,E)$, where each edge $e \in E$ has capacity $u_e\in\{1,2,\cdots,U\}$.
    \item A source node $s \in V$
    \item A sink node $t\in V$
\end{itemize}
We wish to find a feasible flow $f\in \mathbb{R}^m$ from $s$ to $t$, maximizing $\text{val}(f)=\sum_{e=(s,\cdot)}f_e,$ subject to the following constraints:
\begin{itemize}
        \item For all $e \in E, f_e \leq u_e$
        \item For all $e, f_e \geq 0$
        \item For all $v \notin \{s,t\}, \sum_{e = (v,\cdot)}f_e = \sum_{e = (\cdot, v)}f_e$
\end{itemize}
Intuitively, this means that we have positive flow through each edge, the flow through each edge is bounded by its capacity, and the flow into a vertex is equal to the flow out. 
\subsection{Ford-Fulkerson with scaling}
Recall that the Ford-Fulkerson algorithm \cite{FF56} has a runtime $O(mf^*).$ Given a flow $f$, the residual graph $G_f$ has capacities $u_e-f_e$. Since the source can have $O(n)$ neighbors, and each can have capacity up to $U,$ in the worst case we have $f^*=O(nU)$ so Ford-Fulkerson takes $O(mnU)$ time in the worst-case scenario.

We will show that Max Flow can be solved in $O(m^2 \log U)$ time.  Note that all capacities are integers and can be represented with length $\log U$ binary strings. We write the binary string representations of capacities as rows in a grid, and append a column of zeros to teh left. We iterate from left to right, and at each step, we first double the capacity of each edge and double the flow through that edge, resulting in a max flow on the new capacitated graph. We then add one unit of capacity to any edge with a $1$ in the current column. Note that the flow we had previously is no longer a max flow for the current graph.

Recall that the max flow problem is equivalent to the min cut problem, so the original flow was a fully-saturated min cut. Since we added at most $m$ units of capacity at the most recent step, there exists a cut of capacity at most $m$ on the residual graph, so the max flow through the residual graph is at most $m$. Therefore running Ford-Fulkerson takes $O(m^2)$ time. There are $\log U$ columns since we have length $\log U$ bitstrings so this takes $O(m^2 \log U)$ time to find a max flow for the original graph.
\bibliographystyle{alpha}

\begin{thebibliography}{42}

\bibitem{BNW22}
Aaron Bernstein, Danupon Nanongkai, and Christian Wulff-Nilsen.
\newblock Negative-weight
single-source shortest paths in near-linear time. 
\newblock {\em Proceedings of the 63rd Annual IEEE
Symposium on Foundations of Computer Science (FOCS)}, 600--611, 2022.
\bibitem{FF56}
Lester R. Ford and Delbert R. Fulkerson.
\newblock Maximal flow through a network.. 
\newblock {\em . Canadian Journal
of Mathematics}, 8(3):399404, 1956

\end{thebibliography}

\end{document}

\end{document}

