summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--graph/euler.cpp41
-rw-r--r--graph/graph.tex2
-rw-r--r--tcr.pdfbin313827 -> 313603 bytes
-rw-r--r--tcr.tex7
4 files changed, 49 insertions, 1 deletions
diff --git a/graph/euler.cpp b/graph/euler.cpp
new file mode 100644
index 0000000..74b3399
--- /dev/null
+++ b/graph/euler.cpp
@@ -0,0 +1,41 @@
+vector< vector<int> > adjlist;
+vector< vector<int> > otherIdx;
+vector<int> cycle;
+vector<int> validIdx;
+
+void swapEdges(int n, int a, int b) { // Vertauscht Kanten mit Indizes a und b von Knoten n.
+ int neighA = adjlist[n][a];
+ int neighB = adjlist[n][b];
+ int idxNeighA = otherIdx[n][a];
+ int idxNeighB = otherIdx[n][b];
+ swap(adjlist[n][a], adjlist[n][b]);
+ swap(otherIdx[n][a], otherIdx[n][b]);
+ otherIdx[neighA][idxNeighA] = b;
+ otherIdx[neighB][idxNeighB] = a;
+}
+
+void removeEdge(int n, int i) { // Entfernt Kante i von Knoten n (und die zugehoerige Rueckwaertskante).
+ int other = adjlist[n][i];
+ if (other == n) { //Schlingen
+ validIdx[n]++;
+ return;
+ }
+ int otherIndex = otherIdx[n][i];
+ validIdx[n]++;
+ if (otherIndex != validIdx[other]) {
+ swapEdges(other, otherIndex, validIdx[other]);
+ }
+ validIdx[other]++;
+}
+
+//findet Eulerzyklus an Knoten n startend
+//teste vorher, dass Graph zusammenhaengend ist! (isolierte Punkte sind ok)
+//teste vorher, ob Eulerzyklus ueberhaupt existiert!
+void euler(int n) {
+ while (validIdx[n] < (int)adjlist[n].size()) {
+ int nn = adjlist[n][validIdx[n]];
+ removeEdge(n, validIdx[n]);
+ euler(nn);
+ }
+ cycle.push_back(n); //Zyklus am Ende in cycle
+} \ No newline at end of file
diff --git a/graph/graph.tex b/graph/graph.tex
index 5982e5a..fada803 100644
--- a/graph/graph.tex
+++ b/graph/graph.tex
@@ -21,7 +21,9 @@ Kürzestes Pfade in Graphen mit negativen Kanten. Erkennt negative Zyklen.
\item Zyklus existiert, wenn jeder Knoten geraden Grad hat (ungerichtet), bzw. bei jedem Knoten Ein- und Ausgangsgrad übereinstimmen (gerichtet).
\item Pfad existiert, wenn alle bis auf (maximal) zwei Knoten geraden Grad haben (ungerichtet), bzw. bei allen Knoten bis auf zwei Ein- und Ausgangsgrad übereinstimmen, wobei einer eine Ausgangskante mehr hat (Startknoten) und einer eine Eingangskante mehr hat (Endknoten).
\item \textbf{Je nach Aufgabenstellung überprüfen, wie isolierte Punkte interpretiert werden sollen.}
+ \item Der Code unten läuft in Linearzeit. Wenn das nicht notwenidg ist (oder bestimmte Sortierungen verlangt werden), gehts mit einem \lstinline{set} einfacher.
\end{itemize}
+\lstinputlisting{graph/euler.cpp}
\subsection{Max-Flow (\textsc{Edmonds-Karp}-Algorithmus)}
\lstinputlisting{graph/edmondsKarp.cpp} \ No newline at end of file
diff --git a/tcr.pdf b/tcr.pdf
index eec39ab..c735878 100644
--- a/tcr.pdf
+++ b/tcr.pdf
Binary files differ
diff --git a/tcr.tex b/tcr.tex
index 3e6a0ed..cea7d08 100644
--- a/tcr.tex
+++ b/tcr.tex
@@ -44,13 +44,18 @@
\usepackage[top=2cm, bottom=2cm, left=2cm, right=1cm]{geometry}
+\usepackage{multicol}
+
\title{Team Contest Reference}
\author{ChaosKITs \\ Karlsruhe Institute of Technology}
\begin{document}
\maketitle
-\tableofcontents
+\setlength{\columnsep}{1cm}
+\begin{multicols}{2}
+ \tableofcontents
+\end{multicols}
\newpage
\input{datastructures/datastructures}