Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. // хранение графа ч/з списки смежности
  7.  
  8. int main() {
  9. int n,m;
  10. cin >> n >> m;
  11. vector<vector<int> > v(n);
  12.  
  13. for (int i = 0; i < m; i++) {
  14. int s,f;
  15. cin >> s >> f;
  16. v[s].push_back(f);
  17. v[f].push_back(s);
  18. }
  19.  
  20. for (int i = 0; i < n; i++){
  21. for (int j = 0; j < v[i].size(); j++)
  22. cout << v[i][j] << " ";
  23. cout << endl;
  24. }
  25.  
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement