提交记录 6895


用户 题目 状态 得分 用时 内存 语言 代码长度
GavinZheng 2002. 【NOIP2018】旅行(加强版) Runtime Error 20 119.888 ms 588904 KB C++11 1.38 KB
提交时间 评测时间
2018-11-13 22:12:43 2020-08-01 00:53:38
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define maxn 550000
struct gg{
	int to,from,next;
}side[2*maxn];
int n,m,on[maxn],head[maxn],dfn[maxn],tot;
bool use=0;
int cnt=0;
void insert(int u,int v){
	struct gg a={v,u,head[u]};side[++cnt]=a;head[u]=cnt;return; 
}
bool visit[maxn],pre[maxn];
bool cir(int now,int fa){
	pre[now]=1;
	for(int i=head[now];i;i=side[i].next){
		int u=side[i].to;
		if(u==fa)continue;
		if(pre[u]){
			on[u]=1;on[now]=1;return 1;
		}
		if(cir(u,now)){
			if(on[now]){
				return 0;
			}
			else{
				on[now]=1;return 1;
			}
		}
	}
	return 0;
}
void dfs(int now,int mem){
	if(visit[now])return;
	visit[now]=1;
	dfn[++tot]=now;
	int data[maxn],tg=0;
	for(int i=head[now];i;i=side[i].next){
		int u=side[i].to;
		if(visit[u])continue;
		data[++tg]=u;
	}
	//cout<<data[1]<<endl;
	if(!tg)return;	
	sort(data+1,data+1+tg);
	for(int i=1;i<=tg;i++){
		if(visit[data[i]])continue;
		if(data[i]>mem&&mem&&!use){
			use=1;return;
		}
		if(on[now]&&on[data[i]]&&i!=tg){
			dfs(data[i],data[i+1]);
		}
		else if(tg==i){
			dfs(data[i],mem);
		}
		else{
			dfs(data[i],0);
		}
		
	}
	return;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int u,v;scanf("%d%d",&u,&v);
		insert(u,v);insert(v,u);
	}
	if(n==m){
		use=0;
		cir(1,0);
		use=0;dfs(1,0);
	}
	else{
		use=1;
		dfs(1,0);
	}
	for(int i=1;i<=tot;i++){
		printf("%d ",dfn[i]);
	}
return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1601.73 us8 MB + 456 KBAcceptedScore: 5

Testcase #2601.97 us8 MB + 460 KBAcceptedScore: 5

Testcase #37.018 ms102 MB + 888 KBAcceptedScore: 5

Testcase #48.393 ms123 MB + 868 KBAcceptedScore: 5

Testcase #538.6 ms575 MB + 104 KBRuntime ErrorScore: 0

Testcase #638.6 ms575 MB + 104 KBRuntime ErrorScore: 0

Testcase #744.427 ms575 MB + 104 KBRuntime ErrorScore: 0

Testcase #844.355 ms575 MB + 104 KBRuntime ErrorScore: 0

Testcase #970.76 ms575 MB + 104 KBRuntime ErrorScore: 0

Testcase #1070.36 ms575 MB + 104 KBRuntime ErrorScore: 0

Testcase #1170.565 ms575 MB + 104 KBRuntime ErrorScore: 0

Testcase #1270.673 ms575 MB + 104 KBRuntime ErrorScore: 0

Testcase #1339.087 ms575 MB + 104 KBRuntime ErrorScore: 0

Testcase #1438.884 ms575 MB + 104 KBRuntime ErrorScore: 0

Testcase #1547.253 ms575 MB + 104 KBRuntime ErrorScore: 0

Testcase #1647.347 ms575 MB + 104 KBRuntime ErrorScore: 0

Testcase #17119.817 ms575 MB + 104 KBRuntime ErrorScore: 0

Testcase #18119.888 ms575 MB + 104 KBRuntime ErrorScore: 0

Testcase #19108.816 ms575 MB + 104 KBRuntime ErrorScore: 0

Testcase #20115.243 ms575 MB + 104 KBRuntime ErrorScore: 0


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