暴力删边,暴力枚举
#include <bits/stdc++.h> using namespace std; #define MAXM 5010 inline int read()
{
int x = ,ff = ;char ch = getchar();
while(!isdigit(ch))
{
if(ch == '-') ff = -;
ch = getchar();
}
while(isdigit(ch))
{
x = (x << ) + (x << ) + (ch ^ );
ch = getchar();
}
return x * ff;
} inline void write(int x)
{
if(x < ) putchar('-'),x = -x;
if(x > ) write(x / );
putchar(x % + '');
} int a,b,x,y,dx,dy,top = ,c[MAXM],vis[MAXM],T[MAXM],m[MAXM],e[MAXM][];
vector < int > q[MAXM]; inline void dfs(int x)
{ T[++top] = x; vis[x] = true;
int l = q[x].size();
for(int i = ;i < l;++i)
{
int y = q[x][i];
if((vis[y]) || (x == dx && y == dy) || (x == dy && y == dx)) continue;
dfs(y);
}
return ;
} inline void check()
{
for(int i = ;i <= a;++i)
{
if(m[i] != T[i])
{
if(m[i] < T[i]) return ;
break;
}
}
for(int i = ;i <= a;++i)
m[i] = T[i];
} int main()
{
memset(m,0x3f,sizeof(m));
a = read(); b = read();
for(int i = ;i <= b;++i)
{
int x,y;
x = read(); y = read();
q[x].push_back(y);
q[y].push_back(x);
e[i][] = x;
e[i][] = y;
}
for(int i = ;i <= a;++i)
sort(q[i].begin(),q[i].end());
if(b == a - )
{
dx = -; dy = -;
dfs();
for(int i = ;i <= a;++i)
write(T[i]),putchar(' ');
}
else
{
for(int i = ;i <= b;++i)
{
top = ;
dx = e[i][];
dy = e[i][];
memset(T,,sizeof(T));
memset(vis,false,sizeof(vis));
dfs();
if(top != a) continue;
check();
}
for(int i = ;i <= a;++i)
write(m[i]),putchar(' ');
}
return ;
}