This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector < int > tours;
vector < vector < int > > adj;
vector < vector < bool > > visited;
void tour(int u, int s, vector < int >& aux, int streets) {
aux.push_back(u);
for (auto v : adj[u]) {
if (v == s && streets == m - 1) {
tours = aux;
} else {
if (!visited[u][v]) {
visited[u][v] = visited[v][u] = true;
tour(v, s, aux, streets + 1);
}
}
}
aux.pop_back();
}
int main()
{
cin >> n >> m;
adj = vector < vector < int > > (n, vector < int >());
visited = vector < vector < bool > > (n, vector < bool >(n, false));
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
--u; --v;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector < int > aux;
tour(0, 0, aux, 0);
for (int i : tours)
cout << i + 1 << " ";
cout << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |