From c498a66df48f4a52b2b73a1ce7ca8001b2cc92bc Mon Sep 17 00:00:00 2001 From: Jérémy Zurcher Date: Sun, 13 Nov 2016 23:06:17 +0100 Subject: Algorithms : add 03-algorithms_on_graphs 03-paths_in_graphs --- .../03-paths_in_graphs/01-bfs/bfs.cpp | 27 ++++++++++++++++++++++ .../03-paths_in_graphs/01-bfs/tests/01 | 6 +++++ .../03-paths_in_graphs/01-bfs/tests/01.a | 1 + .../03-paths_in_graphs/01-bfs/tests/02 | 6 +++++ .../03-paths_in_graphs/01-bfs/tests/02.a | 1 + 5 files changed, 41 insertions(+) create mode 100644 03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/bfs.cpp create mode 100644 03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/01 create mode 100644 03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/01.a create mode 100644 03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/02 create mode 100644 03-algorithms_on_graphs/03-paths_in_graphs/01-bfs/tests/02.a (limited to '03-algorithms_on_graphs/03-paths_in_graphs/01-bfs') 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 +#include +#include + +using std::vector; +using std::queue; + +int distance(vector > &adj, int s, int t) { + //write your code here + return -1; +} + +int main() { + int n, m; + std::cin >> n >> m; + vector > adj(n, vector()); + 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 -- cgit v1.2.3