提交记录 6911


用户 题目 状态 得分 用时 内存 语言 代码长度
shanjb020221 2002. 【NOIP2018】旅行(加强版) Accepted 100 228.967 ms 79512 KB C++ 1.94 KB
提交时间 评测时间
2018-11-16 13:24:23 2020-08-01 00:53:54
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define IO(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;
const int N=500010,inf=20020221;
inline int read() {
	register char c=getchar(),d=0;
	while(c>'9'||c<'0')d=c,c=getchar();
	register int r=0;
	while(c>='0'&&c<='9')r=(r<<1)+(r<<3)+c-'0',c=getchar();
	return d=='-'?-r:r;
}
inline void wt(int x) {
	if(x/10)wt(x/10);
	putchar(x%10+'0');
}
inline void wtln(int x) {
	if(x<0)x=-x,putchar('-');
	wt(x),putchar('\n');
}
inline void wtsp(int x) {
	if(x<0)x=-x,putchar('-');
	wt(x),putchar(' ');
}
struct edge {
	int to,nt,id;
	inline void init(int t,int n,int i) {
		to=t,nt=n,id=i;
	}
} e[N<<1],te[N<<1];
int h[N],c=1,x,y,tc=1,th[N];
inline void addt(int f,int t,int i) {
	te[++tc].init(t,th[f],i),th[f]=tc;
	te[++tc].init(f,th[t],i),th[t]=tc;
}
inline void adde(int f,int t,int i) {
	e[++c].init(t,h[f],i),h[f]=c;
}
int n,m;
int ans[N],tot;
int stp[N],top;
int vis[N];
int ocp[N],del;
inline bool fndc(int pos,int pi=0) {
	vis[pos]=1;
	for(int i=h[pos],tps; i; i=e[i].nt) {
		tps=e[i].to;
		if(e[i].id==pi)continue;
		stp[++top]=pos;
		if(vis[tps]) {
			while(1) {
				ocp[stp[top]]=1;
				if(stp[top--]==tps)break;
			}
			return 1;
		} else if(fndc(tps,e[i].id))return 1;
		if(stp[top]==pos)--top;
	}
	return 0;
}
int tmp[N],cnt;
inline void dfs(int pos,int nex=inf) {
	vis[pos]=1,ans[++tot]=pos;
	int l=cnt,r;
	for(int i=h[pos]; i; i=e[i].nt)if(!vis[e[i].to])tmp[cnt++]=e[i].to;
	r=cnt;
	for(int i=l,j=l+1; i<r; i=j,++j) {
		if(vis[tmp[i]])continue;
		while(j<r&&vis[tmp[j]])++j;
		if(j<r)dfs(tmp[i],tmp[j]);
		else if(del==0&&ocp[pos]&&ocp[tmp[i]]&&tmp[i]>nex)del=1;
		else dfs(tmp[i],nex);
	}
}
int main() {
	n=read(),m=read();
	for(int i=1; i<=m; ++i)addt(read(),read(),i);
	for(int pos=n; pos>=1; --pos)
		for(int i=th[pos]; i; i=te[i].nt)
			adde(te[i].to,pos,te[i].id);
	fndc(1);
	memset(vis,0,sizeof vis);
	dfs(1);
	for(int i=1; i<n; ++i)wtsp(ans[i]);
	wtln(ans[n]);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1195.16 us1 MB + 996 KBAcceptedScore: 5

Testcase #2202.97 us1 MB + 1000 KBAcceptedScore: 5

Testcase #3201.95 us1 MB + 1000 KBAcceptedScore: 5

Testcase #4210.36 us1 MB + 1000 KBAcceptedScore: 5

Testcase #5665.01 us2 MB + 528 KBAcceptedScore: 5

Testcase #6660.99 us2 MB + 504 KBAcceptedScore: 5

Testcase #716.519 ms12 MB + 552 KBAcceptedScore: 5

Testcase #816.637 ms11 MB + 128 KBAcceptedScore: 5

Testcase #9219.718 ms55 MB + 556 KBAcceptedScore: 5

Testcase #10224.773 ms59 MB + 248 KBAcceptedScore: 5

Testcase #11221.045 ms48 MB + 520 KBAcceptedScore: 5

Testcase #12227.094 ms52 MB + 512 KBAcceptedScore: 5

Testcase #13680.79 us2 MB + 568 KBAcceptedScore: 5

Testcase #14668.63 us2 MB + 644 KBAcceptedScore: 5

Testcase #1516.03 ms13 MB + 748 KBAcceptedScore: 5

Testcase #1616.409 ms14 MB + 560 KBAcceptedScore: 5

Testcase #17227.635 ms77 MB + 664 KBAcceptedScore: 5

Testcase #18228.967 ms77 MB + 664 KBAcceptedScore: 5

Testcase #19196.091 ms58 MB + 472 KBAcceptedScore: 5

Testcase #20214.434 ms69 MB + 164 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-09 07:21:58 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠