From ce9f41f580f6b24c46e5ca5af2d21fde273b45d6 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Tue, 4 Nov 2025 09:47:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0P5022=E9=A2=98?= =?UTF-8?q?=E7=9A=84DFS=E8=A7=A3=E6=B3=95=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实现基于优先队列的DFS遍历算法,用于解决图论题目P5022。使用bitset标记访问节点,确保正确遍历无向图。 --- src/11/3/P5022.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/11/3/P5022.cpp diff --git a/src/11/3/P5022.cpp b/src/11/3/P5022.cpp new file mode 100644 index 0000000..031f96d --- /dev/null +++ b/src/11/3/P5022.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using ll = int64_t; + +const ll maxn = 5000+7; +ll n,m; +std::vector,std::greater>> e; +std::bitset b; + +static inline void dfs(ll f,ll now){ + // printf("dfs f=%lld, now=%lld\n",f,now); + std::cout<>n>>m; + e.resize(n+1); + for(ll i=1;i<=m;i++){ + ll u,v; + std::cin>>u>>v; + e[u].push(v); + e[v].push(u); + } + dfs(0,1); + std::cout<<"\n"; +} \ No newline at end of file