summaryrefslogtreecommitdiffstats
path: root/03-algorithms_on_graphs/03-paths_in_graphs/01-bfs
diff options
context:
space:
mode:
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