Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <fstream>
  2. #include <vector>
  3. using namespace std;
  4. ifstream cin("conex.in");
  5. ofstream cout("conex.out");
  6. const int DIM = 101;
  7. int a[DIM][DIM], q[DIM], viz[DIM], t[DIM];
  8. void bfs(int x, int nc);
  9. int n;
  10. int main()
  11. {
  12. int m, k;
  13. cin >> n;
  14. int x, y;
  15. while(cin >> x >> y)
  16. {
  17. a[x][y] = a[y][x] = 1;
  18. }
  19. int conex = 0;
  20. bfs(1, conex + 1);
  21. return 0;
  22. }
  23.  
  24. void bfs(int k, int nc)
  25. {
  26. int st, dr, nod;
  27. st = dr = 0;
  28. q[st] = k;
  29. viz[k] = nc;
  30. while(st <= dr)
  31. {
  32. nod = q[st++];
  33. for(int i = 1; i <= n; ++i)
  34. {
  35. if(a[nod][i])
  36. {
  37. if(!viz[i])
  38. {
  39. q[++dr] = i;
  40. viz[i] = nc;
  41. t[i] = nod;
  42. }
  43. }
  44. }
  45. }
  46. if(n == dr + 1)
  47. cout << "DA";
  48. else
  49. cout << "NU";
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement