提交记录 6891


用户 题目 状态 得分 用时 内存 语言 代码长度
GavinZheng 2002. 【NOIP2018】旅行(加强版) Runtime Error 40 6.554 ms 83996 KB C++ 1.37 KB
提交时间 评测时间
2018-11-13 22:02:08 2020-08-01 00:53:20
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define maxn 5500
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 #141.99 us140 KBAcceptedScore: 5

Testcase #241.62 us144 KBAcceptedScore: 5

Testcase #3122.21 us1 MB + 84 KBAcceptedScore: 5

Testcase #4136.24 us1 MB + 300 KBAcceptedScore: 5

Testcase #55.034 ms59 MB + 448 KBAcceptedScore: 5

Testcase #64.647 ms53 MB + 488 KBAcceptedScore: 5

Testcase #7218.69 us400 KBRuntime ErrorScore: 0

Testcase #8230.54 us404 KBRuntime ErrorScore: 0

Testcase #9686.45 us1 MB + 944 KBRuntime ErrorScore: 0

Testcase #10713.44 us1 MB + 944 KBRuntime ErrorScore: 0

Testcase #11267.73 us988 KBRuntime ErrorScore: 0

Testcase #12325.58 us1 MB + 364 KBRuntime ErrorScore: 0

Testcase #135.298 ms62 MB + 972 KBAcceptedScore: 5

Testcase #146.554 ms82 MB + 28 KBAcceptedScore: 5

Testcase #15241.43 us404 KBRuntime ErrorScore: 0

Testcase #16220.84 us396 KBRuntime ErrorScore: 0

Testcase #17475.76 us1 MB + 940 KBRuntime ErrorScore: 0

Testcase #18487.2 us1 MB + 924 KBRuntime ErrorScore: 0

Testcase #19889.18 us1 MB + 944 KBRuntime ErrorScore: 0

Testcase #20331.08 us1 MB + 396 KBRuntime ErrorScore: 0


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