Advertisement
Mirbek

От матрицы смежности к спискам смежности

Jan 8th, 2022
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 105;
  6.  
  7. int n;
  8. int a[N][N];
  9. vector <int> g[N];
  10.  
  11. int main(){
  12.     cin >> n;
  13.  
  14.     int cnt = 0;
  15.     for (int i = 1; i <= n; i++) {
  16.         for (int j = 1; j <= n; j++) {
  17.             cin >> a[i][j];
  18.             if (a[i][j]) {
  19.                 g[i].push_back(j);
  20.             }
  21.         }
  22.     }
  23.  
  24.     for (int i = 1; i <= n; i++) {
  25.         cout << g[i].size() << " ";
  26.         for (int j = 0; j < g[i].size(); j++) {
  27.             cout << g[i][j] << " ";
  28.         }
  29.         cout << endl;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement