Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stack>
- #include <sstream>
- #include <vector>
- using namespace std;
- // n - number of tops
- // return if sequence is Eilerov path
- stack<int> st;
- int main()
- {
- ios::sync_with_stdio(false);
- string str;
- stringstream ss;
- vector<bool> visited(1000001, false);
- int x;
- getline(cin, str);
- ss << str;
- int temp = -1;
- while (ss >> x) {
- if (st.size() == 0 && temp == -1) {
- temp = x;
- continue;
- }
- if (x == temp) {
- cout << "NO";
- return 0;
- }
- if (st.size() > 0 && x == st.top()) {
- st.pop();
- temp = x;
- continue;
- }
- if (visited[x] == true) {
- cout << "NO";
- return 0;
- }
- visited[temp] = true;
- st.push(temp);
- temp = x;
- }
- if (st.size() > 0) {
- cout << "NO";
- }
- else {
- cout << "YES";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement