提交记录 6912


用户 题目 状态 得分 用时 内存 语言 代码长度
shanjb020221 2002. 【NOIP2018】旅行(加强版) Accepted 100 214.669 ms 86916 KB C++ 2.78 KB
提交时间 评测时间
2018-11-16 13:29:06 2020-08-01 00:53:58
#include<cstdio>
#include<cstring>
#define IO(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
const int str=1<<22;
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;
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;
	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.33 us1 MB + 996 KBAcceptedScore: 5

Testcase #2168.59 us1 MB + 1000 KBAcceptedScore: 5

Testcase #3178.61 us1 MB + 1000 KBAcceptedScore: 5

Testcase #4176.85 us1 MB + 1000 KBAcceptedScore: 5

Testcase #5569.49 us2 MB + 600 KBAcceptedScore: 5

Testcase #6568.76 us2 MB + 576 KBAcceptedScore: 5

Testcase #715.118 ms14 MB + 232 KBAcceptedScore: 5

Testcase #815.151 ms12 MB + 832 KBAcceptedScore: 5

Testcase #9208.241 ms62 MB + 792 KBAcceptedScore: 5

Testcase #10212.661 ms66 MB + 484 KBAcceptedScore: 5

Testcase #11209.134 ms55 MB + 756 KBAcceptedScore: 5

Testcase #12214.669 ms59 MB + 744 KBAcceptedScore: 5

Testcase #13585.04 us2 MB + 640 KBAcceptedScore: 5

Testcase #14571.32 us2 MB + 712 KBAcceptedScore: 5

Testcase #1514.331 ms15 MB + 428 KBAcceptedScore: 5

Testcase #1614.567 ms16 MB + 240 KBAcceptedScore: 5

Testcase #17212.283 ms84 MB + 900 KBAcceptedScore: 5

Testcase #18212.352 ms84 MB + 900 KBAcceptedScore: 5

Testcase #19182.774 ms65 MB + 708 KBAcceptedScore: 5

Testcase #20200.354 ms76 MB + 400 KBAcceptedScore: 5


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