1. Abridged Problem Statement
Given a connected undirected graph G with N vertices and M edges (3 ≤ N ≤ 10000, M ≤ 100000) that satisfies:
- Every vertex has degree ≥ 2.
- Any vertex of degree exactly 2 has its two neighbors non-adjacent.
- Any vertex of degree > 2 has at least one neighbor of degree 2, and all its other neighbors form a clique.
Either find a Hamiltonian cycle (visit every vertex exactly once, returning to the start) or report –1 if none exists.

2. Detailed Editorial

Overview
----------
Vertices split naturally into "chain" vertices (degree = 2) and "hub" vertices (degree > 2). Every hub is attached to exactly one chain-vertex leading off to another hub (possibly itself) and has all its other hub-neighbors directly connected, forming a clique. This gives G a "chain-of-cliques" structure. To build a Hamiltonian cycle, we need to:
 1. Verify parity constraints among hubs.
 2. Pick one chain-edge for each hub to serve as its "exit," then perform a tailored DFS that stitches chain-segments and clique-edges into a single cycle.

Step 1: Match hubs and check parity
------------------------------------
- We ignore all degree-2 vertices and explore the subgraph induced by hubs (degree>2).
- Whenever a hub v is visited, we record one of its degree-2 neighbors as `next_node[v]`.
- We recursively count how many hubs lie in v's connected component of the hub-subgraph.
- If any component has an odd number of hubs, no Hamiltonian cycle can exist → print –1 and stop.

Step 2: Build the cycle via special DFS
----------------------------------------
We reset visited-flags and do a DFS starting from vertex 0 with a Boolean flag `in_path=false`. At each vertex u:
 1. Mark u visited.
 2. If u is a hub and its recorded `next_node[u]` is unvisited, first DFS into that chain-vertex.
 3. Then for each unvisited neighbor v of u:
    – If u is a chain-vertex (deg=2), simply DFS(v).
    – Else (u is a hub), only DFS(v) if it is a hub and `in_path==false`; that ensures we use the clique-edges exactly once.
 4. After exploring all, push u onto a stack.

At the end, the stack (reversed) is a Hamiltonian cycle if it contains all N vertices; otherwise –1.

Why it works
-------------
- The parity check enforces that the multigraph of hubs (where hubs are connected whenever there is a chain-path between them) is Eulerian, allowing us to pair up all "entry" and "exit" points.
- The DFS weaving chain-edges (`next_node`) and clique-edges ensures each vertex is visited exactly once, building a single cycle over all vertices.

Complexities
------------
O(N+M) time and memory, well within the given limits.

3. C++ Solution
```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
}

int n, m;
vector<vector<int>> adj;
vector<bool> visited;
vector<int> next_node, hcycle;

void add_edge(int u, int v) {
    adj[u].push_back(v);
    adj[v].push_back(u);
}

int match_nodes(int u, int root) {
    int ans = 1;
    visited[u] = true;
    for(int v: adj[u]) {
        if(adj[v].size() == 2) {
            next_node[u] = v;
        } else if(adj[v].size() > 2 && !visited[v]) {
            ans += match_nodes(v, root);
        }
    }
    return ans;
}

void dfs(int u, bool in_path) {
    visited[u] = true;
    if(adj[u].size() > 2 && !visited[next_node[u]]) {
        dfs(next_node[u], false);
    }
    for(int v: adj[u]) {
        if(!visited[v]) {
            if(adj[u].size() == 2) {
                dfs(v, false);
            } else if(!in_path && adj[v].size() > 2) {
                dfs(v, true);
            }
        }
    }
    hcycle.push_back(u);
}

void read() {
    cin >> n >> m;
    adj.assign(n, {});
    visited.assign(n, false);
    next_node.assign(n, -1);

    for(int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        add_edge(u, v);
    }
}

void solve() {
    // The strange-graph conditions force a rigid structure: every high-degree
    // vertex (deg > 2) has a unique degree-2 neighbour that must be used to
    // exit it on the cycle, and high-degree vertices come in even-sized
    // clusters (cliques connected through degree-2 bridges). next_node[u]
    // records, for each high-degree u, the forced degree-2 neighbour. We first
    // verify every cluster of adjacent high-degree vertices has even size
    // (otherwise no Hamiltonian cycle exists), then run a single DFS that
    // walks the forced edges to lay out the cycle in hcycle. If the walk does
    // not visit all n vertices, no cycle exists.

    for(int i = 0; i < n; i++) {
        if(adj[i].size() > 2 && !visited[i]) {
            if(match_nodes(i, i) & 1) {
                cout << "-1\n";
                return;
            }
        }
    }

    fill(visited.begin(), visited.end(), false);
    hcycle.clear();
    dfs(0, false);

    if((int)hcycle.size() != n) {
        cout << "-1\n";
    } else {
        reverse(hcycle.begin(), hcycle.end());
        for(int u: hcycle) {
            cout << u + 1 << " ";
        }
        cout << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        solve();
    }

    return 0;
}
```

4. Python Solution
```python
import sys
sys.setrecursionlimit(10**7)

def read_input():
    n, m = map(int, sys.stdin.readline().split())
    adj = [[] for _ in range(n)]
    for _ in range(m):
        u, v = map(int, sys.stdin.readline().split())
        u -= 1; v -= 1
        adj[u].append(v)
        adj[v].append(u)
    return n, adj

def match_nodes(u):
    """
    DFS only over hubs (deg>2).
    Mark visited_hub[u] = True, choose one deg-2 neighbor next_node[u].
    Return count of hubs in this component.
    """
    visited_hub[u] = True
    cnt = 1
    for v in adj[u]:
        if len(adj[v]) == 2:
            # v is chain-vertex: record as exit for u
            next_node[u] = v
        elif len(adj[v]) > 2 and not visited_hub[v]:
            cnt += match_nodes(v)
    return cnt

def dfs(u, in_path):
    """
    Main traversal weaving chain-edges and clique-edges.
    in_path=True means we've already used the clique-edge out of u.
    """
    visited[u] = True

    # If u is a hub and its chosen chain-vertex is unvisited, go there first
    if len(adj[u]) > 2:
        w = next_node[u]
        if w != -1 and not visited[w]:
            dfs(w, False)

    # Explore remaining neighbors
    for v in adj[u]:
        if not visited[v]:
            if len(adj[u]) == 2:
                # chain-vertex: always go
                dfs(v, False)
            elif not in_path and len(adj[v]) > 2:
                # hub->hub via clique-edge, only once
                dfs(v, True)

    # post-order push
    hcycle.append(u)

def main():
    n, _adj = read_input()
    global adj, visited_hub, visited, next_node, hcycle
    adj = _adj

    # Step 1: parity check among hubs
    visited_hub = [False]*n
    next_node = [-1]*n
    for i in range(n):
        if len(adj[i]) > 2 and not visited_hub[i]:
            c = match_nodes(i)
            if c % 2 == 1:
                print(-1)
                return

    # Step 2: build the Hamiltonian cycle
    visited = [False]*n
    hcycle = []
    dfs(0, False)

    if len(hcycle) != n:
        print(-1)
    else:
        # reverse the post-order to get the cycle
        hcycle.reverse()
        print(" ".join(str(u+1) for u in hcycle))

if __name__ == "__main__":
    main()
```

5. Compressed Editorial
We partition G into hubs (deg>2) and chains (deg=2). Each hub is linked via one chain-edge to another hub and has a clique among its other hub-neighbors. First, we DFS over hubs only, picking for each hub one chain-neighbor and verifying each hub-component has even size; odd → no cycle. Then we reset and perform a special DFS starting at node 0 that alternates:
  - At a hub, traverse its chosen chain-neighbor first,
  - Then traverse exactly one clique-edge to another hub,
  - At chain-vertices, continue straightforwardly.
Post-order collection of vertices (reversed) yields a Hamiltonian cycle if we visited all N vertices. Otherwise, output –1.
