PAT 甲级 1021 Deepest Root (25 分)

【AFAC2026金融智能-赛题四】我做了一个疯狂的决定,把Embedding和Reranker全删了 本文介绍了AFAC2026金融智能挑战赛赛道四的解题思路,核心是在500万token的严格限制下实现金融长文本的高效问答。作者通过四步流水线(规划、BM25检索、记忆压缩、LLM推理)优化流程,重点创新在于: 采用零API调用的纯BM25检索,配合多路查询、封面页加权和页面邻接扩展等策略 设计高效的检索算法,从问题中提取专有名词并构建多路查询组合 深入理解评分公式,平衡准确率和token消耗,最终在准确率提升的同时将token消耗从数百万降至百万级 这些创新使方案在严格限制下实现了性能突破,展示了在资源受限 阅读详情

Note

  • 图的遍历
  • BFS
  • bfs中可以尽量减少if-else,不必要的判断可以放到bfs之外
  • 用set可以避免排序 (set有序),而且保证不会重复。但是set的遍历只能用迭代器!

Code

#include<bits/stdc++.h>
using namespace std;

struct Node{
	int root,height;
	Node(int r,int h){
		root=r;
		height=h;
	}
};

int n;
vector<int> v[10010];
set<int> ans;
bool isvisit[10010]={false};

int bfs(int root){
	int maxHeight=-1;
	queue<Node> q;
	q.push(Node(root,0));
	while(!q.empty()){
		Node data=q.front();
		q.pop();
		isvisit[data.root]=true;
		for(int i=0;i<v[data.root].size();i++){
			int num=v[data.root][i];
			if(isvisit[num]==false){
				q.push(Node(num,data.height+1));
			}
		}
		if(data.height>maxHeight)
			maxHeight=data.height;
	}
	return maxHeight;
}

int main(){
	#ifndef ONLINE_JUDGE
	freopen("data.txt","r",stdin);
	#endif
	
	int a,b,cnt=0;
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(int i=1;i<=n;i++){
		if(isvisit[i]==false){
			int tmp=bfs(i);
			cnt++;
		}		
	}
	if(cnt!=1) printf("Error: %d components",cnt);
	else{
		int maxheight=-1;
		for(int i=1;i<=n;i++){
			memset(isvisit,false,sizeof(isvisit));
			int h=bfs(i);
			if(h>maxheight){
				maxheight=h;
				ans.clear();
				ans.insert(i);
			}
			else if(h==maxheight){
				ans.insert(i);
			}
		}
		for(set<int>::iterator it=ans.begin();it!=ans.end();++it)
			printf("%d\n",*it);
	}
	
	return 0;
}
自私兽群优化器(SHO)详解:从生物本能到智能优化 自私兽群优化器(SHO)是一种受动物群体自私行为启发的智能优化算法。该算法模拟动物在捕食威胁下的两种行为:聚集行为(全局搜索)和自私行为(局部搜索),将优化问题的解空间映射为生存环境,候选解视为猎物个体。SHO通过安全性评估将猎物分为安全、危险和高危三类,分别采用不同的位置更新策略,并引入捕食者角色增加选择压力。相比传统优化算法,SHO具有无需梯度信息、自适应平衡探索与开发、参数简单等优势,特别适合高维复杂和多模态优化问题。算法通过马尔可夫链理论保证收敛性,已在工程设计和数据挖掘等领域展现出良好性能。 阅读详情

相关推荐

【SABRE 3D, SABRE 3DxT,LAM设备】2025年9月10日

前文:SABRE 3D系列机台简介本章节详细阐述了在维护期间锁定电气、机械、热力学及重力组件以及化学管线输入的锁定操作流程,旨在降低人员受伤风险。p42~p55。

weixin_46735260的博客 1615

【PAT甲级】1021 Deepest Root (25分)

题目链接:1021Deepest Root(25分) #include <iostream> #include <vector> using namespace std; int DFS(int s, vector<int> &vis, vector<int> adj[], int k){ int maxDepth = 0; vis[s] = 1; for(int i = 0; i < adj[s].size...

五百零一 129

EV1527 vs HS1527:固定码芯片的STM32解码避坑指南

本文深入解析EV1527与HS1527固定码芯片的技术差异,提供基于STM32的完整解码方案与稳定性优化策略。通过硬件接口配置、状态机实现及示波器诊断,解决工业遥控、安防报警等场景中的解码难题,特别针对时序差异和干扰问题给出实用解决方案。

o0p1q2r3的博客 331

PAT真题练习(甲级)1021 Deepest Root (25 分)

PAT真题练习(甲级)1021 Deepest Root (25 分) 原题网址: https://pintia.cn/problem-sets/994805342720868352/problems/994805482919673856 A graph which is connected and acyclic can be considered a tree. The height of...

Be Quick & Clever & Lucky 396

在 SAP ABAP 里可靠地对接 FTP 服务器:从连接、命令到传输与排错的完整实战

本文详细介绍了在SAP ABAP中实现FTP文件交换的完整技术方案。文章首先解析了FTP协议的双连接特性(控制连接与数据连接),强调保持控制连接的重要性。随后详细说明了ABAP中FTP操作的四步标准流程:建立连接(包含HTTP_SCRAMBLE加密)、执行命令、断开连接和关闭RFC通道。文章提供了实战案例代码,演示如何将FTP文件复制到应用服务器再读取进内表处理,特别指出后台作业与前台操作的关键差异。最后总结了常见错误排查要点,包括连接模型、路径设置和资源释放等问题。全文通过SAP标准函数模块的调用顺序、典

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 309

【Windows Server 2019】发布服务器 | 远程桌面服务的安装与配置 Ⅰ——理论,实验拓扑和安装基于RemoteAPP的RDS

博客介绍了Windows Server中远程桌面服务的理论,实验拓扑以及基于RemoteAPP的RDS安装。博文介绍了如何在Windows Server上部署发布服务器。

VMware, Windows, Linux, Cisco, Container, Kubernetes, Kali 6129

PAT甲级 - 1021 Deepest Root (25 分)

题目链接:PAT甲级 - 1021 Deepest Root (25 分) A graph which is connected and acyclic can be considered a tree. The hight of the tree depends on the selected root. Now you are supposed to find the root that r...

231

Codex入门19-数据库操作(解放双手:用自然语言写SQL、建表和数据迁移)

写 SQL 是后端开发的日常,但复杂的 JOIN、子查询、窗口函数总让人头疼。本文教你用 Codex CLI 实现:自然语言直接生成 CREATE TABLE、复杂 SQL 查询、数据库迁移脚本(Prisma/Knex/Alembic)、ORM 模型代码(SQLAlchemy/TypeORM)、甚至自动生成数据库文档。重点强调安全红线——永远不要让 AI 直接连接生产数据库。从需求描述到完整数据库层代码,一篇搞定。

yueyeguzhuo的专栏 234

PAT甲级 1021 Deepest Root (25分)

1021 Deepest Root (25分) 题目链接:PAT A 1021 题目大意:给出一个数n代表节点的个数(节点编号1-n),给出各个边的连接方式,问哪个节点为根节点时,这棵树最高,如果有多个这样的结点,则按升序的方式输出。如果给出的图不是一棵树,那么输出它有几个部分组成。 思路分析:注意题中输入第一行是节点数目,接下来的n-1行是边。由于连通,节点数为n,边为n-1的图一定是一棵树...

weixin_43684054的博客 307

车载以太网-组播

车载以太网-组播

天赐好车的博客 254

税务某局 webpack 登录接口逆向分析

我们再回到接口逻辑去看一下,发现每次请求前,还有两个接口,getpublickey和sendsm4,这里分析了一下调用逻辑,sm4这个接口用到一个参数是由publickey返回的一个参数而来,这个参数又经过内部加密处理,我们找到这个参数加密的地方,大概是在这个位置。我们还是顺着逻辑将加载器扣下来,然后用一个变量去接收,有了加载器,我们直接把加密代码扣下来做下处理,把一些用到的参数整理下如下。打上断点分析后,_utils_getuuid这个很长的变量也是加载器的一个函数,我们将这段代码也扣下来,如下。

码王吴彦祖的博客 402

PAT甲级-1021 Deepest Root (25分)

点击链接PAT甲级-AC全解汇总 题目: A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highe...

卷子的博客 336

YOLOv11改进 | 注意力篇 | YOLOv11引入CA注意力机制

摘要:最近关于移动网络设计的研究已经证明了通道注意力(例如,挤压和激励注意力)对于提升模型性能的显着有效性,但它们通常忽略了位置信息,而位置信息对于生成空间选择性注意力图很重要。到此本文的正式分享内容就结束了,在这里给大家推荐我的YOLOv11改进有效涨点专栏,本专栏目前为新开的,后期我会根据各种前沿顶会进行论文复现,也会对一些老的改进机制进行补充,如果大家觉得本文帮助到你了,订阅本专栏,关注后续更多的更新~3.2 在Extramodule里创建CA。在CA.py文件里添加给出的CA代码。

tsg6698的博客 2980

【PAT甲级题解记录】1021 Deepest Root (25 分)

问题描述 求一个N个点N-1条边的图是否能构成二叉树,能的话输出能形成最大深度的根结点,不能的话输出联通分支数。 解题思路 一开始还以为要分别看回路和联通分支,但这道题给的数据N点N-1条边保证了这两种情况只会同时出现,那就简单很多了,直接暴力就可以过题。

retr0的博客 379

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

PAT甲级1021 Deepest Root (25 分)题解

\quad这个题暴力也可以过,我试过枚举每一个点开始进行dfs,记录从这个点开始到其他节点的最大深度和对应的节点,记录下来,相互比较得到答案,时间需要1000ms,题目给的限制是2000ms,完全够。 \quad正确解法是从树任一点a开始遍历,记录下距离a最远的顶点集合res1,再从res1中任选一个顶点开始第二次遍历,记录下距离该顶点最远的顶点集合res2,答案就是res1和res2中顶点去重...

qq_40438165的博客 1636

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Day46: [PAT甲级] 1021 Deepest Root (25分)

Day46: [PAT甲级] 1021 Deepest Root (25分) 题源: 来自PAT真题库: https://pintia.cn/problem-sets/994805342720868352/problems/994805482919673856 代码: dirty code凑合看吧 #include<iostream> #include<string> #...

qq2215459786的博客 161

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

1021 Deepest Root (25 分)--PAT甲级

1021 Deepest Root (25 分) A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a h...

laplacebh的博客 995

1021 Deepest Root (25 分)-PAT甲级

A graph(图表) which is connected and acyclic(非循环的,非周期的) can be considered a tree. The height of the tree depends on the selected(选择的) root. Now you are supposed to find the root that results in a highest tree. Such a root is calledthe deepest root. Input S.

神笔码农.的博客 746

PAT甲级1021 Deepest Root (25 分)

1021Deepest Root(25分) A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a ...

Dexter 191

PAT-甲级-1021 Deepest Root (25 分)

1021Deepest Root(25分) A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a ...

valcanoshan的博客 192

PAT 甲级 1021 Deepest Root (25分)

题目 1021 Deepest Root (25分) A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root is called the deepest root. I

qq_41001689的博客 154

PAT甲级 -- 1021 Deepest Root (25 分)

A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root ...

猪の成长日记 372

PAT 甲级 1021 Deepest Root (25分)

A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root ...

weixin_41514525的博客 152

PAT 1021 Deepest Root (25 分) -甲级

1021 Deepest Root (25 分) A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a h...

qq_39071488的博客 189

PAT甲级1021 Deepest Root (25分)|C++实现

一、题目描述 原题链接 A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root is called the deepest root. Input Specificat

weixin_42393947的博客 199
上一篇: PAT 甲级 1098 Insertion or Heap Sort (25 分)
下一篇: PAT 甲级 1013 Battle Over Cities (25 分)
HHCCCaptain
博客等级 码龄6年 8粉丝 104原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值