提交记录 6888


用户 题目 状态 得分 用时 内存 语言 代码长度
shanjb020221 2002. 【NOIP2018】旅行(加强版) Accepted 100 193.011 ms 77564 KB C++ 1.94 KB
提交时间 评测时间
2018-11-13 19:24:56 2020-08-01 00:53:11
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define IO(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define I(x) freopen(x".in","r",stdin)
#define R(x) freopen(x".ini","r",stdin),freopen(x".in","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];
int h[N],c=1,x,y;
inline void adde(int f,int t,int i) {
	e[++c].init(t,h[f],i),h[f]=c;
	e[++c].init(f,h[t],i),h[t]=c;
}
int n,m;
int ans[N],tot;

int ste[N],stp[N],top;
int cre[N],crp[N],cc,vis[N];
int oce[N],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(i==pi)continue;
		ste[++top]=i;
		stp[top]=pos;
		if(vis[tps]) {
			while(1) {
				ocp[stp[top]]=oce[e[ste[top]].id]=1;
				if(stp[top--]==tps)break;
			}
			return 1;
		} else if(fndc(tps,i^1))return 1;
		if(ste[top]==i)--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,sort(tmp+l,tmp+r);
	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() {
	IO("travel");
	n=read(),m=read();
	for(int i=1; i<=m; ++i)
		adde(read(),read(),i);
	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.31 us1 MB + 996 KBAcceptedScore: 5

Testcase #2203.46 us1 MB + 1004 KBAcceptedScore: 5

Testcase #3210.17 us1 MB + 1000 KBAcceptedScore: 5

Testcase #4202.77 us1 MB + 1000 KBAcceptedScore: 5

Testcase #5650.43 us2 MB + 444 KBAcceptedScore: 5

Testcase #6647.09 us2 MB + 416 KBAcceptedScore: 5

Testcase #715.091 ms10 MB + 820 KBAcceptedScore: 5

Testcase #814.938 ms9 MB + 44 KBAcceptedScore: 5

Testcase #9167.835 ms46 MB + 948 KBAcceptedScore: 5

Testcase #10169.963 ms51 MB + 516 KBAcceptedScore: 5

Testcase #11168.714 ms38 MB + 216 KBAcceptedScore: 5

Testcase #12171.345 ms43 MB + 156 KBAcceptedScore: 5

Testcase #13672.11 us2 MB + 512 KBAcceptedScore: 5

Testcase #14667.02 us2 MB + 604 KBAcceptedScore: 5

Testcase #1514.785 ms12 MB + 580 KBAcceptedScore: 5

Testcase #1615.046 ms13 MB + 588 KBAcceptedScore: 5

Testcase #17193.011 ms75 MB + 764 KBAcceptedScore: 5

Testcase #18192.911 ms75 MB + 764 KBAcceptedScore: 5

Testcase #19160.036 ms51 MB + 1016 KBAcceptedScore: 5

Testcase #20179.156 ms65 MB + 248 KBAcceptedScore: 5


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