n個點m條無向邊
輸出一條哈密頓回路
#include#include #include using namespace std; const int N = 155; int n, m; bool mp[N][N]; int S, T, top, Stack[N]; bool vis[N]; void _reverse(int l,int r) { while (l >n>>m) { memset(mp, 0, sizeof mp); for (int i = 1, u, v; i <= m; i++) { scanf("%d %d",&u, &v); mp[u][v] = mp[v][u] = 1; } hamiltun(1); for (int i = 0; i < top; i++) printf("%d%c", Stack[i], i==top-1?'\n':' '); } return 0; }