传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3918
【题解】
每日至少更一题啊qwq凑任务(迷
明显猜个结论:随便搜环就行了
然后搜环姿势错了我也很无奈啊。。。
# include <stdio.h>
# include <string.h>
# include <algorithm>
// # include <bits/stdc++.h>using namespace std;typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = + ;
const int mod = 1e9+;# define RG register
# define ST staticint n, m;
int head[M], nxt[M], to[M], tot = ;
inline void add(int u, int v) {
++tot; nxt[tot] = head[u]; head[u] = tot; to[tot] = v;
}
inline void adde(int u, int v) {
add(u, v);
add(v, u);
}bool vis[M];
int Final;
int c[M], cn, p[M];inline void dfs(int x) {
if(p[x] != -) {
printf("%d", x);
for (int i=p[x]+; i<=cn; ++i) {
printf(" %d", c[i]);
p[c[i]] = -;
}
puts("");
cn = p[x];
return;
}
c[++cn] = x;
p[x] = cn;
for (int i=head[x]; i; i=nxt[i]) {
if(vis[i] || vis[i^]) continue;
head[x] = nxt[i];
vis[i] = ;
dfs(to[i]);
if(p[x] == -) break;
}
}int main() {
scanf("%d%d", &n, &m);
for (int i=; i<=m; ++i) {
int u, v; scanf("%d%d", &u, &v);
adde(u, v);
} for (int i=; i<=n; ++i) p[i] = -; for (int i=; i<=tot; i++)
if(!vis[i] && !vis[i^])
dfs(to[i]); return ;
}