fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n, m, u, v;
  8. cin >> n >> m;
  9. vector <vector <int> > e(n);
  10.  
  11. for (int i = 0; i < m; i++)
  12. {
  13. cin >> u >> v;
  14. e[u-1].push_back(v);
  15. }
  16.  
  17. cout << n << endl;
  18.  
  19. for (int i = 0; i < n; i++)
  20. {
  21. cout << e[i].size() << " ";
  22. sort(e[i].begin(), e[i].end());
  23.  
  24. for (int j = 0; j < e[i].size(); j++)
  25. cout << e[i][j] << " ";
  26.  
  27. cout << endl;
  28. }
  29. }
Success #stdin #stdout 0s 4452KB
stdin
	4 6
1 2
3 1
3 2
3 4
4 2
4 3
stdout
4
1 2 
0 
3 1 2 4 
2 2 3