fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ffor(i,o,f) for(int i = o; i < f; i++)
  5. #define pb push_back
  6. #define mp make_pair
  7. #define all(a) (a).begin(), (a).end()
  8. #define F first
  9. #define S second
  10. #define PI 3.14159265358979323846264338327950
  11. #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  12. #define endl '\n'
  13. #define sz(x) ((int)(x).size())
  14. typedef long long ll;
  15. typedef pair < int, int > pii;
  16. typedef vector < int > vi;
  17. typedef vector < pii > vii;
  18. typedef vector < vi > gi;
  19. typedef vector < ll > vll;
  20. typedef map < int, int > mii;
  21.  
  22. int t, n, m, u, v, groups;
  23. const int tam = 1005;
  24. int mat[tam][tam];
  25. unordered_set < int > vis;
  26.  
  27. void dfs(int nd){
  28. vis.insert(nd);
  29. ffor(i, 0, tam){
  30. if(mat[nd][i] && vis.find(i) == vis.end()){
  31. dfs(i);
  32. }
  33. }
  34. }
  35.  
  36. int main()
  37. {
  38. mat[0][2] = mat[2][0] = 4;
  39. mat[0][3] = mat[3][0] = 2;
  40. mat[1][6] = mat[6][1] = 2;
  41. mat[1][3] = mat[3][1] = 7;
  42. mat[6][7] = mat[7][6] = 8;
  43. mat[3][7] = mat[7][3] = 3;
  44. mat[2][3] = mat[3][2] = 6;
  45. mat[2][4] = mat[4][2] = 1;
  46. mat[2][5] = mat[5][2] = 3;
  47. mat[4][5] = mat[5][4] = 5;
  48.  
  49. dfs(0);
  50. }
  51.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty