summaryrefslogtreecommitdiff
path: root/graphs/task1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'graphs/task1.cpp')
-rw-r--r--graphs/task1.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/graphs/task1.cpp b/graphs/task1.cpp
new file mode 100644
index 0000000..62806ae
--- /dev/null
+++ b/graphs/task1.cpp
@@ -0,0 +1,60 @@
+#include<iostream>
+#include<vector>
+
+using namespace std;
+
+typedef vector<vector<int>> graph;
+
+void print(graph g)
+{
+ for (int i = 0; i < int(g.size()); ++i)
+ {
+ cout << i + 1 << ": ";
+ for (auto node : g[i])
+ cout << node + 1 << ", ";
+ cout << endl;
+ }
+
+}
+
+int main()
+{
+ cout << "Введите количество вершин: ";
+ int n;
+ cin >> n;
+
+ cout << "Введите количество рёбер: ";
+ int k;
+ cin >> k;
+
+ graph g(n);
+
+ cout << "o----------------------o" << endl;
+ cout << "| Нумерация вершин с 1 |" << endl;
+ cout << "o----------------------o" << endl;
+
+
+ cout << "Введите рёбра (ориентированные):" << endl;
+ for (int i = 0; i < k; ++i)
+ {
+ int a, b;
+ cin >> a >> b;
+ a--;
+ b--;
+ g[a].push_back(b);
+ }
+
+ cout << "Введённый граф:" << endl;
+ print(g);
+
+ cout << "Введите исследуемую вершину: ";
+ int q;
+ cin >> q;
+ q--;
+
+ cout << "С данной вершиной смежны "
+ << g[q].size()
+ << " вершин" << endl;
+
+ return 0;
+}