提交记录 6982


用户 题目 状态 得分 用时 内存 语言 代码长度
TimeTraveller 2002. 【NOIP2018】旅行(加强版) Accepted 100 456.304 ms 76576 KB C++ 1.31 KB
提交时间 评测时间
2018-12-01 07:56:29 2020-08-01 00:56:02
#include<vector> 
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
const int M=5e5+10;
const int inf=1e9;
vector <int> vec[M];
void add(int a,int b){
	vec[a].push_back(b);
	vec[b].push_back(a);
}
bool vis[M],cir[M],finded;
int stk[M],up;
void dfs_cir(int a,int b){
	vis[a]=1;stk[++up]=a;
	for(int i=0,sz=vec[a].size(),v;i<sz;i++){
		v=vec[a][i];
		if(finded) return;
		if(v==b) continue;
		if(vis[v]){
			finded=1;
			for(;up&&stk[up]!=v;--up){
				cir[stk[up]]=1;
			}	cir[stk[up--]]=1;
			return;
		}else{
			dfs_cir(v,a);
		}
	}
	vis[stk[up--]]=0;
}

int ans[M],tot,ls[M],top,delet;
void dfs_ans(int a,int nex){
	vis[a]=1;ans[++tot]=a;
	int p=top+1,q;
	for(int i=0,sz=vec[a].size(),v;i<sz;i++){
		v=vec[a][i];
		if(!vis[v])ls[++top]=v;
	}
	q=top;
	for(int i=p,j=p+1;i<=q;i=j,j++){
		if(vis[ls[i]]) continue;
		while(j<=q&&vis[ls[j]])++j;
		if(j<=q)dfs_ans(ls[i],ls[j]);
		else if(!delet&&cir[a]&&cir[ls[i]]&&ls[i]>nex)delet=1;
		else dfs_ans(ls[i],nex);
	}
}
int a,b,n,m;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&a,&b);
		add(a,b);
	}
	for(int i=1;i<=n;i++){sort(vec[i].begin(),vec[i].end());}
	if(m==n-1){
		dfs_ans(1,inf);
	}else{
		dfs_cir(1,1);
		memset(vis,0,sizeof(vis));
		dfs_ans(1,inf);
	}
	for(int i=1;i<n;i++) printf("%d ",ans[i]);printf("%d",ans[n]);
	return 0;
} 

CompilationN/AN/ACompile OKScore: N/A

Testcase #12.018 ms11 MB + 492 KBAcceptedScore: 5

Testcase #22.052 ms11 MB + 984 KBAcceptedScore: 5

Testcase #32.036 ms11 MB + 500 KBAcceptedScore: 5

Testcase #42.011 ms11 MB + 500 KBAcceptedScore: 5

Testcase #53.611 ms11 MB + 928 KBAcceptedScore: 5

Testcase #63.573 ms11 MB + 908 KBAcceptedScore: 5

Testcase #738.885 ms19 MB + 708 KBAcceptedScore: 5

Testcase #839.374 ms18 MB + 344 KBAcceptedScore: 5

Testcase #9358.68 ms53 MB + 156 KBAcceptedScore: 5

Testcase #10361.57 ms56 MB + 692 KBAcceptedScore: 5

Testcase #11356.843 ms46 MB + 524 KBAcceptedScore: 5

Testcase #12360.98 ms50 MB + 284 KBAcceptedScore: 5

Testcase #133.78 ms12 MB + 424 KBAcceptedScore: 5

Testcase #143.757 ms12 MB + 496 KBAcceptedScore: 5

Testcase #1543.177 ms21 MB + 160 KBAcceptedScore: 5

Testcase #1643.893 ms21 MB + 984 KBAcceptedScore: 5

Testcase #17455.646 ms74 MB + 800 KBAcceptedScore: 5

Testcase #18456.304 ms74 MB + 800 KBAcceptedScore: 5

Testcase #19407.786 ms55 MB + 724 KBAcceptedScore: 5

Testcase #20435.373 ms66 MB + 308 KBAcceptedScore: 5


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