summaryrefslogtreecommitdiff
path: root/graphs/task2.cpp
diff options
context:
space:
mode:
authorAndrew Guschin <saintruler@gmail.com>2021-03-29 13:13:40 +0400
committerAndrew Guschin <saintruler@gmail.com>2021-03-29 13:13:40 +0400
commit85dcaa072faeadc318ec717caa29d1cb94bddd59 (patch)
treed2cfc0f4b8b00a80ab87afade371f63a7ce4b193 /graphs/task2.cpp
parent5a5e997ce29416cc971548d2efeb6b834c96d237 (diff)
Исправил и переименовал первые три задачи
Diffstat (limited to 'graphs/task2.cpp')
-rw-r--r--graphs/task2.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/graphs/task2.cpp b/graphs/task2.cpp
new file mode 100644
index 0000000..17dcdbe
--- /dev/null
+++ b/graphs/task2.cpp
@@ -0,0 +1,62 @@
+#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 << "Введите вершины, которые необходимо соединить:" << endl;
+ int p, q;
+ cin >> p >> q;
+ p--;
+ q--;
+
+ g[p].push_back(q);
+ g[q].push_back(p);
+
+ cout << "Полученный граф:" << endl;
+ print(g);
+
+ return 0;
+}