diff options
Diffstat (limited to 'graphs/task1_1.cpp')
| -rw-r--r-- | graphs/task1_1.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/graphs/task1_1.cpp b/graphs/task1_1.cpp index 3963f5e..140c1bd 100644 --- a/graphs/task1_1.cpp +++ b/graphs/task1_1.cpp @@ -3,6 +3,19 @@ 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() { @@ -14,26 +27,34 @@ int main() int k; cin >> k; - vector<vector<int>> graph(n); + graph g(n); + + cout << "o----------------------o" << endl; + cout << "| Нумерация вершин с 1 |" << endl; + cout << "o----------------------o" << endl; + - cout << "Введите рёбра (неориентированные), нумерация с 1:" << endl; + cout << "Введите рёбра (неориентированные):" << 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); + g[a].push_back(b); + g[b].push_back(a); } + cout << "Введённый граф:" << endl; + print(g); + cout << "Введите исследуемую вершину: "; int q; cin >> q; q--; cout << "С данной вершиной смежны " - << graph[q].size() + << g[q].size() << " вершин" << endl; return 0; |