summaryrefslogtreecommitdiffstats
path: root/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-11-13 23:06:17 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-11-13 23:06:17 +0100
commitc498a66df48f4a52b2b73a1ce7ca8001b2cc92bc (patch)
treef0249c1ae5f19b8aa34ca4228ced61408ac58026 /03-algorithms_on_graphs/03-paths_in_graphs/01-bfs
parenta80b82ef6c4214d16b5c6df76c90fb88f23329f7 (diff)
downloadcoursera-c498a66df48f4a52b2b73a1ce7ca8001b2cc92bc.zip
coursera-c498a66df48f4a52b2b73a1ce7ca8001b2cc92bc.tar.gz
Algorithms : add 03-algorithms_on_graphs 03-paths_in_graphs
Diffstat (limited to '03-algorithms_on_graphs/03-paths_in_graphs/01-bfs')
-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
5 files changed, 41 insertions, 0 deletions
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