fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n, m;
  8. cin >> n;
  9. cin >> m;
  10. int airwayMatrix[n][n] = {};
  11. int sumOfConnections;
  12. bool first;
  13. int args[3];
  14.  
  15. for(int i = 0; i < m; i++)
  16. {
  17. cin >> args[0];
  18. cin >> args[1];
  19. if(args[0] == 1)
  20. {
  21. cin >> args[2];
  22. airwayMatrix[args[1]][args[2]] = 1;
  23. airwayMatrix[args[2]][args[1]] = 1;
  24. }
  25. else if(args[0] == 4)
  26. {
  27. sumOfConnections = 0;
  28. for(int j = 0; j < n; j++)
  29. {
  30. if(airwayMatrix[args[1]][j] == 1)
  31. sumOfConnections++;
  32. }
  33. cout << sumOfConnections << '\n';
  34. }
  35. else if(args[0] == 5)
  36. {
  37. first = true;
  38. for(int j = 0; j < n; j++)
  39. {
  40. if(airwayMatrix[args[1]][j] == 1)
  41. {
  42. if(first)
  43. {
  44. cout << j;
  45. first = false;
  46. }
  47. else
  48. {
  49. cout << " " << j;
  50. }
  51. }
  52. }
  53. cout << '\n';
  54. }
  55. }
  56. return 0;
  57. }
  58.  
Success #stdin #stdout 0s 5416KB
stdin
5 9
1 0 1
1 0 3
1 1 3
4 1
5 0
5 4
1 0 2
1 1 4
5 0
stdout
2
1 3

1 2 3