提交记录 6913


用户 题目 状态 得分 用时 内存 语言 代码长度
shanjb020221 2002. 【NOIP2018】旅行(加强版) Accepted 100 213.82 ms 79568 KB C++ 2.38 KB
提交时间 评测时间
2018-11-16 13:33:55 2020-08-01 00:54:02
#include<cstdio>
#include<cstring>
#define IO(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
const int str=1<<15;
const char* endl="\n";
struct Reader {
	char buf[str],*s,*t;
	Reader():s(buf),t(buf) {};
	inline char gt() {
		return s==t&&((t=(s=buf)+fread(buf,1,str,stdin))==s)?EOF:(*s++);
	}
	template<typename T>Reader&operator>>(T&x) {
		register char c=0,d;
		while(c<'0'||c>'9')d=c,c=gt();
		x=0;
		while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=gt();
		if(d=='-')x=-x;
		return *this;
	}
} cin;
struct Writer {
	char buf[str],*s,*t;
	Writer():s(buf),t(buf+str) {}
	~Writer() {
		fwrite(buf,1,s-buf,stdout);
	}
	inline void pt(char c) {
		(s==t)?(fwrite(s=buf,1,str,stdout),*s++=c):(*s++=c);
	}
	template<typename T>Writer&operator<<(T x) {
		if(!x)return pt('0'),*this;
		if(x<0)pt('-'),x=-x;
		register char a[30],t=0;
		while(x)a[t++]=x%10,x/=10;
		while(t--)pt(a[t]+'0');
		return *this;
	}
	Writer&operator<<(const char*s) {
		while(*s)pt(*s++);
		return *this;
	}
} cout;
const int N=500010,inf=20020221;
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;
	register int i,tps;
	for(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;
	register int l=cnt,r,i,j;
	for(i=h[pos]; i; i=e[i].nt)if(!vis[e[i].to])tmp[cnt++]=e[i].to;
	r=cnt;
	for(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() {
	cin>>n>>m;
	register int i,pos,x,y;
	for(i=1; i<=m; ++i)cin>>x>>y,addt(x,y,i);
	for(pos=n; pos>=1; --pos)
		for(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(i=1; i<n; ++i)cout<<ans[i]<<" ";
	cout<<ans[n]<<endl;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1170.94 us1 MB + 996 KBAcceptedScore: 5

Testcase #2170.21 us1 MB + 1000 KBAcceptedScore: 5

Testcase #3177.18 us1 MB + 1000 KBAcceptedScore: 5

Testcase #4176.18 us1 MB + 1000 KBAcceptedScore: 5

Testcase #5567.13 us2 MB + 580 KBAcceptedScore: 5

Testcase #6566.48 us2 MB + 556 KBAcceptedScore: 5

Testcase #714.702 ms12 MB + 608 KBAcceptedScore: 5

Testcase #814.612 ms11 MB + 184 KBAcceptedScore: 5

Testcase #9207.372 ms55 MB + 612 KBAcceptedScore: 5

Testcase #10211.705 ms59 MB + 304 KBAcceptedScore: 5

Testcase #11208.118 ms48 MB + 576 KBAcceptedScore: 5

Testcase #12213.82 ms52 MB + 564 KBAcceptedScore: 5

Testcase #13587.46 us2 MB + 620 KBAcceptedScore: 5

Testcase #14574.22 us2 MB + 692 KBAcceptedScore: 5

Testcase #1513.824 ms13 MB + 804 KBAcceptedScore: 5

Testcase #1614.053 ms14 MB + 616 KBAcceptedScore: 5

Testcase #17211.518 ms77 MB + 720 KBAcceptedScore: 5

Testcase #18211.465 ms77 MB + 720 KBAcceptedScore: 5

Testcase #19181.69 ms58 MB + 528 KBAcceptedScore: 5

Testcase #20199.35 ms69 MB + 220 KBAcceptedScore: 5


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