summaryrefslogtreecommitdiffstats
path: root/03-algorithms_on_graphs
diff options
context:
space:
mode:
Diffstat (limited to '03-algorithms_on_graphs')
-rw-r--r--03-algorithms_on_graphs/03-paths_in_graphs/00_paths_in_graphs.pdfbin0 -> 372018 bytes
-rw-r--r--03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/bfs.cpp27
-rw-r--r--03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/016
-rw-r--r--03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/01.a1
-rw-r--r--03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/026
-rw-r--r--03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/02.a1
-rw-r--r--03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/bipartite.cpp24
-rw-r--r--03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/015
-rw-r--r--03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/01.a1
-rw-r--r--03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/025
-rw-r--r--03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/02.a1
-rwxr-xr-x03-algorithms_on_graphs/03-paths_in_graphs/check38
12 files changed, 115 insertions, 0 deletions
diff --git a/03-algorithms_on_graphs/03-paths_in_graphs/00_paths_in_graphs.pdf b/03-algorithms_on_graphs/03-paths_in_graphs/00_paths_in_graphs.pdf
new file mode 100644
index 0000000..52bd7d8
--- /dev/null
+++ b/03-algorithms_on_graphs/03-paths_in_graphs/00_paths_in_graphs.pdf
Binary files differ
diff --git a/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/bfs.cpp b/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/bfs.cpp
new file mode 100644
index 0000000..5a6da4b
--- /dev/null
+++ b/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/bfs.cpp
@@ -0,0 +1,27 @@
+#include <iostream>
+#include <vector>
+#include <queue>
+
+using std::vector;
+using std::queue;
+
+int distance(vector<vector<int> > &adj, int s, int t) {
+ //write your code here
+ return -1;
+}
+
+int main() {
+ int n, m;
+ std::cin >> n >> m;
+ vector<vector<int> > adj(n, vector<int>());
+ for (int i = 0; i < m; i++) {
+ int x, y;
+ std::cin >> x >> y;
+ adj[x - 1].push_back(y - 1);
+ adj[y - 1].push_back(x - 1);
+ }
+ int s, t;
+ std::cin >> s >> t;
+ s--, t--;
+ std::cout << distance(adj, s, t);
+}
diff --git a/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/01 b/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/01
new file mode 100644
index 0000000..e9cfe9d
--- /dev/null
+++ b/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/01
@@ -0,0 +1,6 @@
+4 4
+1 2
+4 1
+2 3
+3 1
+2 4
diff --git a/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/01.a b/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/01.a
new file mode 100644
index 0000000..0cfbf08
--- /dev/null
+++ b/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/01.a
@@ -0,0 +1 @@
+2
diff --git a/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/02 b/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/02
new file mode 100644
index 0000000..3ca927e
--- /dev/null
+++ b/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/02
@@ -0,0 +1,6 @@
+5 4
+5 2
+1 3
+3 4
+1 4
+3 5
diff --git a/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/02.a b/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/02.a
new file mode 100644
index 0000000..3a2e3f4
--- /dev/null
+++ b/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/02.a
@@ -0,0 +1 @@
+-1
diff --git a/03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/bipartite.cpp b/03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/bipartite.cpp
new file mode 100644
index 0000000..f97eca5
--- /dev/null
+++ b/03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/bipartite.cpp
@@ -0,0 +1,24 @@
+#include <iostream>
+#include <vector>
+#include <queue>
+
+using std::vector;
+using std::queue;
+
+int bipartite(vector<vector<int> > &adj) {
+ //write your code here
+ return -1;
+}
+
+int main() {
+ int n, m;
+ std::cin >> n >> m;
+ vector<vector<int> > adj(n, vector<int>());
+ for (int i = 0; i < m; i++) {
+ int x, y;
+ std::cin >> x >> y;
+ adj[x - 1].push_back(y - 1);
+ adj[y - 1].push_back(x - 1);
+ }
+ std::cout << bipartite(adj);
+}
diff --git a/03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/01 b/03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/01
new file mode 100644
index 0000000..010643f
--- /dev/null
+++ b/03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/01
@@ -0,0 +1,5 @@
+4 4
+1 2
+4 1
+2 3
+3 1
diff --git a/03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/01.a b/03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/01.a
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/01.a
@@ -0,0 +1 @@
+0
diff --git a/03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/02 b/03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/02
new file mode 100644
index 0000000..2a3fbf4
--- /dev/null
+++ b/03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/02
@@ -0,0 +1,5 @@
+5 4
+5 2
+4 2
+3 4
+1 4
diff --git a/03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/02.a b/03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/02.a
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/03-algorithms_on_graphs/03-paths_in_graphs/02-bipartite/tests/02.a
@@ -0,0 +1 @@
+1
diff --git a/03-algorithms_on_graphs/03-paths_in_graphs/check b/03-algorithms_on_graphs/03-paths_in_graphs/check
new file mode 100755
index 0000000..b73ff99
--- /dev/null
+++ b/03-algorithms_on_graphs/03-paths_in_graphs/check
@@ -0,0 +1,38 @@
+#! /bin/bash
+
+RESET="\033[0m"
+RED="\033[0;31m"
+GREEN="\033[0;32m"
+BROWN="\033[0;33m"
+
+BIN=/tmp/bin
+OUTA=/tmp/_outa
+OUTB=/tmp/_outb
+GPP_OPTS="-std=c++11 -O2"
+
+for path in $(find -name \*.cpp | sort); do
+ src=${path##*/}
+ dir=${path%/*}
+ echo -e "${RED}validate $BROWN$dir$RESET/$GREEN$src$RESET"
+ pushd $dir >/dev/null || exit 1
+ echo -e " ${RED}compile $GREEN$src$RESET" && g++ $GPP_OPTS $src -o $BIN || exit 1
+ if [ -d tests ]; then
+ echo -e " ${RED}check $GREEN$src$RESET"
+ for t in $(find ./tests -name "*[^a~]"|sort); do
+ if [ -f $t -a -f "$t.a" ]; then
+ cat $t | $BIN > $OUTA
+ cat $t.a > $OUTB
+ cmp $OUTA $OUTB >/dev/null
+ if [ $? -ne 0 ]; then
+ echo -e " $BROWN$t$RESET is ${RED}KO$RESET"
+ else
+ echo -e " $BROWN$t$RESET is ${GREEN}ok$RESET"
+ fi
+ fi
+ done
+ else
+ echo -e " ${RED}no tests$RESET"
+ fi
+ popd > /dev/null
+done
+