summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--graph/edmondsKarp.cpp (renamed from maxFlow/edmondsKarp.cpp)4
-rw-r--r--graph/graph.tex7
-rw-r--r--graph/scc.cpp54
-rw-r--r--maxFlow/maxFlow.tex4
-rw-r--r--maxFlow/q.log25
-rw-r--r--sonstiges/.2sat.cpp.kate-swpbin0 -> 325 bytes
-rw-r--r--sonstiges/2sat.cpp63
-rw-r--r--sonstiges/sonstiges.tex7
-rw-r--r--tcr.pdfbin81835 -> 111986 bytes
-rw-r--r--tcr.tex2
10 files changed, 70 insertions, 96 deletions
diff --git a/maxFlow/edmondsKarp.cpp b/graph/edmondsKarp.cpp
index ccfb1d2..26c5b0d 100644
--- a/maxFlow/edmondsKarp.cpp
+++ b/graph/edmondsKarp.cpp
@@ -10,7 +10,7 @@ void augment(int v, int minEdge) {
res[p[v]][v] -= f; res[v][p[v]] += f;
}}
-nt maxFlow() { //first inititalize res, adjList, s and t
+int maxFlow() { //first inititalize res, adjList, s and t
int mf = 0;
while (true) {
f = 0;
@@ -30,5 +30,5 @@ nt maxFlow() { //first inititalize res, adjList, s and t
if (f == 0) break;
mf += f;
}
- return maxFlow;
+ return mf;
} \ No newline at end of file
diff --git a/graph/graph.tex b/graph/graph.tex
new file mode 100644
index 0000000..1c37bc7
--- /dev/null
+++ b/graph/graph.tex
@@ -0,0 +1,7 @@
+\section{Graph}
+
+\subsection{Strongly Connected Components (\textsc{Tarjans}-Algorithmus)}
+\lstinputlisting{graph/scc.cpp}
+
+\subsection{Max-Flow (\textsc{Edmonds-Karp}-Algorithmus)}
+\lstinputlisting{graph/edmondsKarp.cpp} \ No newline at end of file
diff --git a/graph/scc.cpp b/graph/scc.cpp
new file mode 100644
index 0000000..b33616b
--- /dev/null
+++ b/graph/scc.cpp
@@ -0,0 +1,54 @@
+int counter, sccCounter, n; //n == number of vertices
+vector<bool> visited, inStack;
+vector< vector<int> > adjlist;
+vector<int> d, low, sccs;
+stack<int> s;
+
+void visit(int v) {
+ visited[v] = true;
+ d[v] = counter;
+ low[v] = counter;
+ counter++;
+ inStack[v] = true;
+ s.push(v);
+
+ for (int i = 0; i < (int)adjlist[v].size(); i++) {
+ int u = adjlist[v][i];
+ if (!visited[u]) {
+ visit(u);
+ low[v] = min(low[v], low[u]);
+ } else if (inStack[u]) {
+ low[v] = min(low[v], low[u]);
+ }
+ }
+
+ if (d[v] == low[v]) {
+ int u;
+ do {
+ u = s.top();
+ s.pop();
+ inStack[u] = false;
+ sccs[u] = sccCounter;
+ } while(u != v);
+ sccCounter++;
+ }
+}
+
+void scc() {
+ //read adjlist
+
+ visited.clear(); visited.assign(n, false);
+ d.clear(); d.resize(n);
+ low.clear(); low.resize(n);
+ inStack.clear(); inStack.assign(n, false);
+ sccs.clear(); sccs.resize(n);
+
+ counter = 0;
+ sccCounter = 0;
+ for (i = 0; i < n; i++) {
+ if (!visited[i]) {
+ visit(i);
+ }
+ }
+ //sccs has the component for each vertex
+} \ No newline at end of file
diff --git a/maxFlow/maxFlow.tex b/maxFlow/maxFlow.tex
deleted file mode 100644
index a88e5ff..0000000
--- a/maxFlow/maxFlow.tex
+++ /dev/null
@@ -1,4 +0,0 @@
-\section{Max Flows}
-\subsection{\textsc{Edmonds-Karp}-Algorithmus}
-
-\lstinputlisting{maxFlow/edmondsKarp.cpp} \ No newline at end of file
diff --git a/maxFlow/q.log b/maxFlow/q.log
deleted file mode 100644
index 2a742c3..0000000
--- a/maxFlow/q.log
+++ /dev/null
@@ -1,25 +0,0 @@
-This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) (format=pdflatex 2014.5.4) 25 OCT 2014 13:42
-entering extended mode
- restricted \write18 enabled.
- %&-line parsing enabled.
-**tcr.tex
-(/usr/share/texlive/texmf-dist/tex/latex/tools/q.tex
-LaTeX2e <2011/06/27>
-Babel <3.9h> and hyphenation patterns for 7 languages loaded.
-File ignored
-)
-! Emergency stop.
-<*> tcr.tex
-
-*** (job aborted, no legal \end found)
-
-
-Here is how much of TeX's memory you used:
- 7 strings out of 494976
- 248 string characters out of 6179138
- 46219 words of memory out of 5000000
- 3331 multiletter control sequences out of 15000+600000
- 3640 words of font info for 14 fonts, out of 8000000 for 9000
- 14 hyphenation exceptions out of 8191
- 5i,0n,1p,87b,8s stack positions out of 5000i,500n,10000p,200000b,80000s
-! ==> Fatal error occurred, no output PDF file produced!
diff --git a/sonstiges/.2sat.cpp.kate-swp b/sonstiges/.2sat.cpp.kate-swp
new file mode 100644
index 0000000..b688b2e
--- /dev/null
+++ b/sonstiges/.2sat.cpp.kate-swp
Binary files differ
diff --git a/sonstiges/2sat.cpp b/sonstiges/2sat.cpp
deleted file mode 100644
index 627e484..0000000
--- a/sonstiges/2sat.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-vector< vector<int> > adjlist; //adjazenzliste
-vector<int> sccs; //speichert die gefundenen SCCs
-vector<bool> visited; //welcher Knoten ist schon besucht worden (in der DFS)
-vector<bool> inStack; //ist Knoten gerade im Stack
-vector<int> d; //discovery time
-vector<int> low; //wie weit hoch geht's im Tiefensuchbaum
-int counter; //Zaehler fuer discovery time
-stack<int> st; //der Stack
-int sccCounter; //Zaehler fuer SCCs
-
-//Tiefensuche, die starke Zusammenhangskomponenten findet
-void visit(int v) {
- visited[v] = true;
- d[v] = counter;
- low[v] = counter;
- counter++;
- st.push(v);
- inStack[v] = true;
-
- for (int i = 0; i < (int)adjlist[v].size(); i++) {
- int w = adjlist[v][i];
-
- if (!visited[w]) {
- visit(w);
- low[v] = min(low[v], low[w]);
- } else if (inStack[w]) {
- low[v] = min(low[v], low[w]);
- }
- }
-
- if (low[v] == d[v]) {
- int next;
- do {
- next = st.top();
- st.pop();
- sccs[next] = sccCounter;
- inStack[next] = false;
- } while (next != v);
-
- sccCounter++;
- }
-}
-
-void solve() {
- //adjlist initialisieren
- //(a || b) wird zu (!a => b) und (!b => a)
-
- visited.clear(); visited.assign(adjlist.size(), false);
- inStack.clear(); inStack.assign(adjlist.size(), false);
- d.clear(); d.assign(adjlist.size(), false);
- low.clear(); low.assign(adjlist.size(), false);
- sccs.clear(); sccs.resize(adjlist.size());
-
- counter = 0;
- sccCounter = 0;
- for (i = 0; i < (int)adjlist.size(); i++) {
- if (!visited[i]) {
- visit(i);
- sccCounter++;
- }
- }
- // genau dann loesbar, wenn keine Variable in gleicher SCC wie Negation ist
-} \ No newline at end of file
diff --git a/sonstiges/sonstiges.tex b/sonstiges/sonstiges.tex
index 0befff3..09ea14c 100644
--- a/sonstiges/sonstiges.tex
+++ b/sonstiges/sonstiges.tex
@@ -1,4 +1,9 @@
\section{Sonstiges}
\subsection{2-SAT}
-\lstinputlisting{sonstiges/2sat.cpp} \ No newline at end of file
+\begin{enumerate}
+ \item Bedingungen in 2-CNF formulieren.
+ \item Implikationsgraph bauen, $\left(a \vee b\right)$ wird zu $\neg a \Rightarrow b$ und $\neg b \Rightarrow a$.
+ \item Finde die starken Zusammenhangskomponenten.
+ \item Genau dann lösbar, wenn keine Variable mit ihrer Negation in einer SCC liegt.
+\end{enumerate} \ No newline at end of file
diff --git a/tcr.pdf b/tcr.pdf
index db1ab6c..09ae39b 100644
--- a/tcr.pdf
+++ b/tcr.pdf
Binary files differ
diff --git a/tcr.tex b/tcr.tex
index 11aeecf..9b43116 100644
--- a/tcr.tex
+++ b/tcr.tex
@@ -47,7 +47,7 @@
\tableofcontents
\newpage
-\input{maxFlow/maxFlow}
+\input{graph/graph}
\input{geometry/geometry}
\input{sonstiges/sonstiges}