Live2D

# 【NOIP2018】旅行

一句话题意：



NOIP的D2T1的原数据范围还是很小的，直接枚举环上断每一条边的最小答案即可

#include<bits/stdc++.h>
#define N 500005
using namespace std;

int n,m,u,v;

struct Edge
{
int next,to;
}edge[N<<1];

{
edge[cnt].to=to;
}

{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}

bool book[N],cir[N],hav;
int fa[N];
void dfs1(int u,int fa)
{
book[u]=1;
{
int v=edge[i].to;
if(v==fa) continue;
if(book[v])
{
hav=cir[u]=cir[v]=1;
return;
}
dfs1(v,u);
if(hav&&cir[v])
{
if(cir[u]) hav=0;
cir[u]=1;
return;
}
}
}

queue<int> ans;
void dfs2(int u,int pos)
{
if(book[u]) return;
book[u]=1;
ans.push(u);
priority_queue<int,vector<int>,greater<int> > qq;
{
int v=edge[i].to;
if(v==fa[u]) continue;
if(book[v]) continue;
qq.push(v);
}
while(!qq.empty())
{
int now=qq.top();
qq.pop();
if(!hav&&cir[now]&&now>pos&&qq.empty())
{
hav=1;
return;
}
int nxt=-0x3f3f3f3f;
if(!qq.empty()&&cir[u]) nxt=qq.top();
if(nxt==-0x3f3f3f3f) nxt=pos;
dfs2(now,nxt);
}
}

int main()
{
for(register int i=1;i<=m;++i)
{
}
dfs1(1,1);
memset(book,0,sizeof(book));
hav=0;
dfs2(1,0x3f3f3f3f);
while(!ans.empty())
{
printf("%d ",ans.front());
ans.pop();
}
return 0;
}

/*
6 6
1 2
2 3
2 4
2 5
3 6
4 6
*/


$$\text{这里是tqr，联系我请加QQ735748368}$$
posted @ 2019-11-04 20:53  tqr06  阅读(86)  评论(0编辑  收藏  举报