From 8557b2421ffc5ab15e9aaf50a7dc07f97a926f4e Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Mon, 29 Mar 2021 12:33:14 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B2=D1=83=D1=8E=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87?= =?UTF-8?q?=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- graphs/Makefile | 10 ++++++++-- graphs/task1_1.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 graphs/task1_1.cpp diff --git a/graphs/Makefile b/graphs/Makefile index e37dda1..85306ba 100644 --- a/graphs/Makefile +++ b/graphs/Makefile @@ -5,8 +5,14 @@ COMPILE=$(CXX) $(CFLAGS) task1_1: $(COMPILE) -o task.out task1_1.cpp test1_1: task1_1 - @printf "" | ./task.out - @printf "Answer: \n" + @printf "4\n5\n1 2\n1 3\n1 4\n2 3\n3 4\n1" | ./task.out + @printf "Answer: 3\n" + @printf "4\n5\n1 2\n1 3\n1 4\n2 3\n3 4\n2" | ./task.out + @printf "Answer: 2\n" + @printf "4\n5\n1 2\n1 3\n1 4\n2 3\n3 4\n3" | ./task.out + @printf "Answer: 3\n" + @printf "4\n5\n1 2\n1 3\n1 4\n2 3\n3 4\n4" | ./task.out + @printf "Answer: 2\n" task12_1: $(COMPILE) -o task.out task12_1.cpp 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 +#include + +using namespace std; + + +int main() +{ + cout << "Введите количество вершин: "; + int n; + cin >> n; + + cout << "Введите количество рёбер: "; + int k; + cin >> k; + + vector> 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; +} -- cgit v1.2.3