fork download
  1. // Danh sach ke
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5. const int nmax = 10000;
  6.  
  7. vector <int> g[nmax];
  8.  
  9. int main()
  10. {
  11. freopen("task.inp", "r", stdin);
  12. freopen("task.out", "w", stdout);
  13. int n, m;
  14. cin >> n >> m;
  15. for(int i = 1; i <= m; ++i) {
  16. int u, v; cin >> u >> v;
  17. g[u].push_back(v);
  18. g[v].push_back(u);
  19. }
  20. for(int i = 1; i <= n; ++i) {
  21. cout << i << ": ";
  22. for(int j = 0; j < g[i].size(); ++j) {
  23. cout << g[i][j] << " ";
  24. }
  25. cout << endl;
  26. }
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0.01s 5300KB
stdin
8 14
2 3
2 5
2 7
3 4
3 5
3 7
3 8
4 5
4 7
5 6
5 7
5 8
6 7
7 8
stdout
Standard output is empty