提交记录 11201


用户 题目 状态 得分 用时 内存 语言 代码长度
SkyWT 2002. 【NOIP2018】旅行(加强版) Runtime Error 40 917.469 ms 20528 KB C++ 1.64 KB
提交时间 评测时间
2019-11-05 22:11:03 2020-08-01 02:40:13

#include<bits/stdc++.h>

using namespace std;

inline int read(){
	int ret=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return ret*f;
}

const int maxn=5005,maxe=10005;

int n,m;
int tot=0,lnk[maxn],nxt[maxe],to[maxe];
pair<int,int> edges[maxn];
bool vis[maxn];

int ans[maxn],now[maxn];
pair<int,int> now_block;

int son[maxn][maxn];

void add_edge(int x,int y){
	tot++; to[tot]=y;
	nxt[tot]=lnk[x];lnk[x]=tot;
}

bool check(int x,int y){
	if (x==now_block.first && y==now_block.second) return false;
	if (y==now_block.first && x==now_block.second) return false;
	return true;
}

void DFS(int x){
	vis[x]=true; now[++now[0]]=x;
	for (int i=1;i<=son[x][0];i++)
		if (!vis[son[x][i]] && check(x,son[x][i])) DFS(son[x][i]);
}

bool smaller(){
	for (int i=1;i<=n;i++)
		if (now[i]<ans[i]) return true; else
		if (now[i]>ans[i]) return false;
	return false;
}

int main(){
	#ifdef DEBUG
		freopen("testdata.in","r",stdin);
		freopen("my.out","w",stdout);
	#endif
	n=read();m=read();
	for (int i=1;i<=m;i++){
		int x=read(),y=read();
		add_edge(x,y);add_edge(y,x);
		son[x][++son[x][0]]=y;
		son[y][++son[y][0]]=x;
		edges[i]=make_pair(x,y);
	}
	for (int i=1;i<=n;i++) sort(son[i]+1,son[i]+1+son[i][0]);

	if (m==n-1){
		DFS(1);
		for (int i=1;i<=n;i++) printf("%d ",now[i]);
		printf("\n");
	} else {
		for (int i=1;i<=m;i++){
			memset(vis,0,sizeof(vis));
			now_block=edges[i]; now[0]=0;
			DFS(1);
			if (now[0]!=n) continue;
			if (ans[0]==0 || smaller())
				for (int j=0;j<=n;j++) ans[j]=now[j];
		}
		for (int i=1;i<=n;i++) printf("%d ",ans[i]);
		printf("\n");
	}
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #140.86 us88 KBAcceptedScore: 5

Testcase #247.01 us92 KBAcceptedScore: 5

Testcase #3107.59 us468 KBAcceptedScore: 5

Testcase #4101.64 us468 KBAcceptedScore: 5

Testcase #53.59 ms19 MB + 984 KBAcceptedScore: 5

Testcase #63.593 ms19 MB + 964 KBAcceptedScore: 5

Testcase #734.14 us52 KBRuntime ErrorScore: 0

Testcase #833.56 us48 KBRuntime ErrorScore: 0

Testcase #932.82 us52 KBRuntime ErrorScore: 0

Testcase #1033.85 us52 KBRuntime ErrorScore: 0

Testcase #1133.86 us56 KBRuntime ErrorScore: 0

Testcase #1232.96 us52 KBRuntime ErrorScore: 0

Testcase #13892.86 ms19 MB + 1020 KBAcceptedScore: 5

Testcase #14917.469 ms20 MB + 48 KBAcceptedScore: 5

Testcase #1535.06 us52 KBRuntime ErrorScore: 0

Testcase #1635.32 us52 KBRuntime ErrorScore: 0

Testcase #1733.82 us52 KBRuntime ErrorScore: 0

Testcase #1833.87 us52 KBRuntime ErrorScore: 0

Testcase #1932.91 us52 KBRuntime ErrorScore: 0

Testcase #2033.79 us56 KBRuntime ErrorScore: 0


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