fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, m;
  6. cin >> n >> m;
  7. vector<vector<int>> graf(n);
  8. for(int i = 0; i < m; i++){
  9. int a, b;
  10. cin >> a >> b;
  11. graf[a].push_back(b);
  12. graf[b].push_back(a);
  13. }
  14. for(int i = 0; i < n; i++) {
  15. sort(begin(graf[i]), end(graf[i]));
  16. for(int s : graf[i]) {
  17. cout << s << " ";
  18. }
  19. cout << endl;
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0s 5348KB
stdin
5
4
1 2
3 1
2 3
2 0
stdout
2 
2 3 
0 1 3 
1 2