#include #include #include #include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); ifstream in("maxpath.in"); cin.rdbuf(in.rdbuf()); ofstream out("maxpath.out"); cout.rdbuf(out.rdbuf()); int N, M; map > edges; cin >> N >> M; vector path; for(int i = 1; i <= N; i++){ edges.insert(make_pair(i, path)); } for(int i = 0; i < M; i++){ int from, to; cin >> from >> to; map >::iterator it = edges.find(from); it->second.push_back(to); it = edges.find(to); it->second.push_back(from); } map >::iterator it = edges.begin(); path.push_back(it->first); bool b = true; while(true){ int index = 0; for(auto el : it->second){ b = true; // cout << "ot " << it->first << " vzimam - " << el; for(auto e : path){ if(el == e){ b = false; } } if(b){ // cout << "svobodno e"; break; } //cout << " veche e izbrano" << endl; index++; } if(!b) break; it = edges.find(it->second[index]); path.push_back(it->first); } cout << path.size() << endl; for(auto el : path) cout << el << endl; }