提交记录 16981


用户 题目 状态 得分 用时 内存 语言 代码长度
2018_Danny 2002. 【NOIP2018】旅行(加强版) Runtime Error 40 858.422 ms 3792 KB C++ 1.81 KB
提交时间 评测时间
2021-11-18 14:59:24 2021-11-18 14:59:30
#include <bits/stdc++.h>

#define R register
#define I inline

using namespace std;

const int N = 5005;

int n, m;
int head[N], tot;
int ans[N], newans[N], dfn, flag, banu, banv;
int buf[20], num;
int cba;

vector <int> e[N];

I int read()
{
	int ret = 0; 
	char ch = getchar();
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch))
	{
		ret = (ret << 1) + (ret << 3) + (ch ^ 48);
		ch = getchar();
	}
	return ret;
}

I void write(int x)
{
    num = 0;
    while (x)
    {
        buf[ ++ num] = x % 10;
        x /= 10;
    }
    for (R int i = num; i; i -- )
        putchar(buf[i] + '0');
    putchar(' ');
}

void dfs(int u, int fa)
{
	if (dfn == n) return;
	newans[ ++ dfn] = u;
	if (newans[dfn] < ans[dfn]) cba = 1;
	else if (cba != 1 && newans[dfn] > ans[dfn])
	{
	    return;
	}
	for (R int i = 0; i < int(e[u].size()); i ++ )
	{
		int v = e[u][i];
		if (v == fa) continue;
		if (u == banu && v == banv) continue;
		if (v == banu && u == banv) continue;
		dfs(v, u);
	}
}

int main()
{
	n = read();
	m = read();
	int u, v;
	for (R int i = 1; i <= m; i ++ )
	{
		u = read();
		v = read();
		e[u].push_back(v);
		e[v].push_back(u);
	}
	for (R int i = 1; i <= n; i ++ )
		sort(e[i].begin(), e[i].end());
	memset(ans, 0x3f, sizeof ans);
	if (m == n - 1) 
	{
		dfs(1, 0);
		for (R int i = 1; i <= n; i ++ )
			ans[i] = newans[i];
	}
	else
	{
		for (R int i = 1; i <= n; i ++ )
			for (R int j = 0; j < int(e[i].size()); j ++ )
			{
				dfn = flag = 0;
				banu = i;
				banv = e[i][j];
				cba = -1;
				dfs(1, 0);
				if (dfn < n) continue;
				for (R int k = 1; k <= n; k ++ )
					if (ans[k] > newans[k]) 
					{
						flag = 1;
						break;
					}
					else if (ans[k] < newans[k]) break; 
				if (flag)
					for (R int k = 1; k <= n; k ++ )
						ans[k] = newans[k];
			}
	} 
	for (R int i = 1; i <= n; i ++ ) write(ans[i]);
	return 0;
} 

CompilationN/AN/ACompile OKScore: N/A

Testcase #151.35 us180 KBAcceptedScore: 5

Testcase #259 us180 KBAcceptedScore: 5

Testcase #371.1 us184 KBAcceptedScore: 5

Testcase #466.74 us184 KBAcceptedScore: 5

Testcase #5876.66 us504 KBAcceptedScore: 5

Testcase #6871.01 us488 KBAcceptedScore: 5

Testcase #7113.58 us736 KBRuntime ErrorScore: 0

Testcase #8155 us1 MB + 52 KBRuntime ErrorScore: 0

Testcase #91.196 ms2 MB + 256 KBRuntime ErrorScore: 0

Testcase #101.146 ms1 MB + 880 KBRuntime ErrorScore: 0

Testcase #11489.06 us3 MB + 720 KBRuntime ErrorScore: 0

Testcase #12287.68 us2 MB + 112 KBRuntime ErrorScore: 0

Testcase #13858.422 ms544 KBAcceptedScore: 5

Testcase #14741.716 ms576 KBAcceptedScore: 5

Testcase #151.059 ms1 MB + 156 KBRuntime ErrorScore: 0

Testcase #16150.58 us1 MB + 8 KBRuntime ErrorScore: 0

Testcase #17230.68 us1 MB + 652 KBRuntime ErrorScore: 0

Testcase #18395.98 us3 MBRuntime ErrorScore: 0

Testcase #191.01 ms816 KBRuntime ErrorScore: 0

Testcase #20106.59 us672 KBRuntime ErrorScore: 0


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