Luogu P5022 旅行
开始写复赛题了
先放张图纪念我惨烈的卡常之路
不说了,简直悲伤
思路么。。不想写了
Code#
//不要在意四十行超级加速,卡常用的
#include<bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
const int MAXN=5e3+10,INF=0x3f3f3f3f;
struct node{
int next,to;
}edge[MAXN<<1];
bool vis[MAXN],better,flag;
vector<int> v[MAXN];
int cnt,Cnt,n,m,del1,del2,x,y;
int head[MAXN],ans[MAXN],Ans[MAXN];
int read()
{
int f=1,a=0;
char ch;
ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-'){
f=-f;
}
ch=getchar();
}
while(ch>='0'&&ch<='9'){
a=a*10+ch-'0';
ch=getchar();
}
return f*a;
}
void addedge(int from,int to)
{
edge[++cnt].to=to;
edge[cnt].next=head[from];
head[from]=cnt;
}
void dfs(int x,int fa)
{
vis[x]=1; Ans[++Cnt]=x;
// cout<<Cnt<<" "<<x<<endl;
for(int i=0;i<v[x].size();i++){
int y=v[x][i];
if(vis[y]||(x==del1 && y==del2)||(x==del2 && y==del1)||y==fa) continue;
dfs(y,x);
}
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// ios::sync_with_stdio(0);
n=read(),m=read();
for(int i=1;i<=m;i++){
x=read(),y=read();
// v[x].push_back(y);
// v[y].push_back
addedge(x,y);
addedge(y,x);
}
for(int i=1;i<=n;++i){
for(int j=head[i];j;j=edge[j].next){
v[i].push_back(edge[j].to);
}
sort(v[i].begin(),v[i].end());
}
memset(ans,INF,sizeof(ans));
if(m==n-1){
dfs(1,0);
for(int i=1;i<=n;++i){
printf("%d ",Ans[i]);
}
}else{
for(int i=1;i<=m;++i){
Cnt=0,flag=0;
memset(vis,0,sizeof(vis)),flag=0;
del1=edge[(i<<1)-1].to;
del2=edge[i<<1].to;
dfs(1,0);
if(Cnt==n){
for(int j=2;j<=n;++j){
if(Ans[j]>ans[j]) break;
if(Ans[j]<ans[j]){
flag=1;
break;
}
}
if(flag){
for(int j=1;j<=n;++j){
ans[j]=Ans[j];
}
}
}
}
for(int i=1;i<=n;++i){
printf("%d ",ans[i]);
}
cout<<endl;
}
return 0;
}