Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stack>
  4. #include <sstream>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. // n - number of tops
  10. // return if sequence is Eilerov path
  11.  
  12. stack<int> st;
  13. int main()
  14. {
  15. ios::sync_with_stdio(false);
  16. string str;
  17. stringstream ss;
  18.  
  19. vector<bool> visited(1000001, false);
  20. int x;
  21. getline(cin, str);
  22. ss << str;
  23. int temp = -1;
  24. while (ss >> x) {
  25. if (st.size() == 0 && temp == -1) {
  26. temp = x;
  27. continue;
  28. }
  29. if (x == temp) {
  30. cout << "NO";
  31. return 0;
  32. }
  33. if (st.size() > 0 && x == st.top()) {
  34. st.pop();
  35. temp = x;
  36. continue;
  37. }
  38. if (visited[x] == true) {
  39. cout << "NO";
  40. return 0;
  41. }
  42. visited[temp] = true;
  43. st.push(temp);
  44. temp = x;
  45. }
  46. if (st.size() > 0) {
  47. cout << "NO";
  48. }
  49. else {
  50. cout << "YES";
  51. }
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement