Задачі
Від матриці суміжності до списків суміжності
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int m;
cin>>m;
int graph[m+1][m+1];
vector<int> res[m+1];
for(int i = 0; i < m; i++){
for(int j = 1; j <= m; j++){
cin>>graph[i][j];
if(graph[i][j] == 1){
res[i].push_back(j);
}
}
}
for(int l = 0; l < m; l++){
cout<<res[l].size()<<" ";
for(auto x : res[l]){
cout<<x<<" ";
}
cout<<endl;
}
return 0;
}