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