Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. //#include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. ifstream cin("conex.in");
  7. ofstream cout("conex.out");
  8. const int kSize = 100000;
  9. int viz[kSize];
  10. vector<vector<int>> g;
  11.  
  12.  
  13. void DFS(int nod)
  14. {
  15. viz[nod] = 1;
  16. //cout << q << ' ';
  17. for (int i = 0; i < g[nod].size(); i += 1)
  18. if( !viz[g[nod][i]]){
  19. DFS(g[nod][i]);
  20. }
  21. }
  22. int main()
  23. {
  24. int m, n, comp = 0;
  25. cin >> n;
  26. g = vector<vector<int>> (n);
  27. int x, y;
  28. while(cin >> x >> y){
  29. x -= 1; y -= 1;
  30. g[x].push_back(y);
  31. g[y].push_back(x);
  32. }
  33. for(int i = 0; i < n; i++)
  34. if(viz[i] == 0){
  35. DFS(i);
  36. comp++;
  37. }
  38. if(comp == 1 )
  39. cout << "DA";
  40. else
  41. cout << "NU";
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement