Advertisement
smatskevich

Lesson25

Mar 28th, 2024
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.   int n; cin >> n;
  8.   // Матрица смежности.
  9.   vector<vector<bool>> matrix(n, vector<bool>(n));
  10.   for (auto& row : matrix) {
  11.     for (int j = 0; j < n; ++j) {
  12.       bool x; cin >> x;
  13.       row[j] = x;
  14.     }
  15.   }
  16.   // Список смежности.
  17.   vector<vector<int>> g(n);
  18.   for (int i = 0; i < n; ++i) {
  19.     for (int j = 0; j < n; ++j) {
  20.       if (matrix[i][j]) {
  21.         g[i].push_back(j);
  22.       }
  23.     }
  24.   }
  25.   for (int u = 0; u < n; ++u) {
  26.     cout << u + 1 << ": ";
  27.     for (int v : g[u]) cout << v + 1 << ", ";
  28.     cout << "\n";
  29.   }
  30.   return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement