1021. Deepest Root (25)

Ubuntu20.04系统笔记本网卡AX211无法找到wifi问题 之前电脑的系统是18.04基本上安装好了系统,可以直接连上wifi,在买了拯救者y9000p2022版本之后,因为网卡太新,安装ubuntu18.04或者20.04之后会没有wifi连接,非常不方便。于是上网找了各种帖子去解决这个问题。具体实现有所不同。 主要参考了这个帖子来解决的:http://t.csdn.cn/7807R 首先: sudo apt install flex bison 然后: git clone https://github.com/intel/backpor. 阅读详情

考察并查集以及树的搜索

#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
//#include<_dbdao.h>
std::vector<bool> visited;
std::vector<int> step;
std::vector<std::vector<int>> edge;
std::vector<int> p;
int n;
int BFS(int s)
{
	visited.assign(n+1, false);
	std::queue<int> q;
	q.push(s);
	visited[s] = true;
	int cnt = 1;//
	step.assign(n+1, 0);
	step[s] = 1;
	int mmax = step[s];
	while(!q.empty())
	{
		int c = q.front();
		q.pop();
		for(int i = 0; i < edge[c].size(); ++i)
		{
			int index = edge[c][i];
			if(!visited[index])
			{
				q.push(index);
				step[index] = step[c]+1;
				mmax = std::max(step[index], mmax);
				visited[index] = true;
				cnt++;
				if(cnt == n) break;
			}
		}
	}
	return mmax;
}
void InitSet()
{
	p.resize(n+1);
	for(int i = 0; i < p.size(); ++i)
		p[i] = i;
}
void CompressSet(int top, int x)
{
	if(p[x] != top)
	{
		CompressSet(top, p[x]);//go to root
		p[x] = top;//when root back, then assign to top
	}
}
int FindSet(int x)
{
	if(x != p[x])
	{
		int t = FindSet(p[x]);//go to root
		CompressSet(t, x);//when root back, then compress
	}
	return p[x];
}
void UnionSet(int x, int y)
{
	int a = FindSet(x);
	int b = FindSet(y);
	p[a] = b;
}
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		edge.clear();
		edge.resize(n+1);
		for(int i = 1; i <= n-1; ++i)
		{
			int a, b;
			scanf("%d%d",&a,&b);
			edge[a].push_back(b);
			edge[b].push_back(a);
		}
		//check if it is a tree
		//construct disjoint set
		InitSet();
		for(int i = 1; i <= n; ++i)
		{
			for(int j = 0; j < edge[i].size(); ++j)
			{
				UnionSet(i, edge[i][j]);
			}
		}
		std::set<int> root;
		for(int i = 1; i <= n; ++i)
			root.insert(FindSet(i));
		if(root.size() != 1)
			printf("Error: %d components\n",root.size());
		else
		{
			//bfs
			//get one endpoint first
			std::set<int> ans;
			int mmax = BFS(1);
			for(int i = 1; i <= n; ++i)
				if(step[i] == mmax) ans.insert(i);
			//get the diameter of the tree
			mmax = BFS(*ans.begin());
			for(int i = 1; i <= n; ++i)
				if(step[i] == mmax) ans.insert(i);
			//output
			std::set<int>::iterator it;
			for(it = ans.begin(); it != ans.end(); it++)
				printf("%d\n",*it);
		}
		
	}

	return 0;
}


 

Kriging克里金模型实现数据回归预测Matlab代码 阅读详情

相关推荐

实验吧 损坏的U盘镜像

        从网站上可以下载一个CTF.hdd的文件,使用winHex打开,可以知道这是一个exFAT格式的文件。        用binwalk检查一下,发现文件中包含两个zip文件,使用foremost进行提取。一个压缩包需要密码解压缩,另一个解压后发现Password.txt文件。说明另一个压缩包的密码与checksum有关。        通过查看exFAT文件系统格式可以得知如何计算...

xingyyn78的博客 3512

1021 Deepest Root (25)(25 分)

1021 Deepest Root (25)(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 i...

CODER的博客 2340

STM32F103串口接收中断:USART_IT_IDLE和USART_IT_RXNE区别

2:如果是大于1个byte的数据,在不用DMA的情况下,同时使能USART_IT_RXNE,USART_IT_IDLE中断,每收到一个字节在中断中把数据存到缓存中,待收到USART_IT_IDLE中断时,收完整帧数据,然后再解析处理数据。比如:如上图在初始化时,同时开启了两个中断,如果传送8个字节的数据,就会产生8个USART_IT_RXNE,和1个USART_IT_IDLE中断。(如果接收到数据,在1个byte的时间内,没有收到新数据,就认为是数据传送完成,产生空闲USART_IT_IDLE中断)

weixin_66299220的博客 2399

1021. Deepest Root (25)-PAT

1021. Deepest Root (25) 时间限制 1500 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A graph which is connected and acyclic can b

兵临城下 2752

ubuntu安装eigen3.3.7

查看已安装版本: gedit /usr/include/eigen3/Eigen/src/Core/util/Macros.h 或 gedit /usr/local/include/eigen3/Eigen/src/Core/util/Macros.h 卸载先前版本: sudo updatedb locate eigen3 得到eigen库的位置 卸载: sudo rm -rf /usr/include/eigen3 /usr/lib/cmake/eigen3 ...

reason的博客 1万+

数学建模:相关性分析学习——皮尔逊(pearson)相关系数与斯皮尔曼(spearman)相关系数

相关性分析:求解相关系数并绘制热力图进行对比

weixin_67565775的博客 8万+

PAT(甲)1021 Deepest Root (25)(详解)

1021 Deepest Root (25)(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...

Invokar的博客 1564

1、语义数据建模:避免陷阱与突破困境

本文探讨了语义数据建模的兴起背景、核心概念、生命周期及常见挑战。从数据丰富型组织和AI开发者的需求出发,分析了语义建模的关键元素和质量维度,并深入讨论了建模过程中可能出现的陷阱与解决方案。文章还针对语义模型的演化、治理和战略组织问题提供了突破思路,旨在帮助数据从业者更好地理解和应用语义建模技术,以提升数据驱动应用的有效性。

c8d9e0f1的博客 119

【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

某AI推荐系统项目管理复盘:架构师总结的6大方法论与调优策略

我是张三,某大厂资深AI架构师,主导过5个千万级用户的推荐系统项目(覆盖电商、内容、视频、音乐、外卖等场景)。我的公众号“AI架构师笔记”会分享更多AI项目管理和技术实战经验,欢迎关注。最后的话:推荐系统不是“一锤子买卖”,而是“持续优化的过程”。希望这篇文章能帮你少踩坑,多做对——毕竟,把复杂的事做成,才是架构师的核心能力。

2501_92132293的博客 362

某城商银行生产容器云平台详细设计方案分享及经验总结

AS3模式的CIS容器部署在K8S集群内,作为F5的控制器,CIS容器通过对K8S集群内Configmap资源进行监控,将Configmap资源中的内容转化为F5的配置,将配置推送给 F5 ,CIS容器还通过K8S标准的API接口完成业务发现和实时监听集群内Pod的变化,一旦Pod发生变化,相应的更新会及时推送给F5,并完成更新。容器技术发展非常迅速,现在应用大多以容器作为承载介质,前两年在容器云上承载的应用类型主要是Web类,随着容器云领域的不断发展,越来越多的应用类型将迁移至容器云,包括有状态应用。

qq_61890005的博客 856

1021 Deepest Root (25 分)c++实现【已AC】

#include&lt;iostream&gt; #include&lt;set&gt; #include&lt;vector&gt; #include&lt;cstdio&gt; using namespace std; const int maxn = 10005; set&lt;int&gt; G[maxn]; bool marked[maxn]{ 0 }; int component = ...

m0_37407587的博客 252

YOLO11改进:轻量级改进 | 通用倒瓶颈(UIB)搜索块结合C3k2二次创新 | 轻量化之王MobileNetV4

通用倒瓶颈(UIB)搜索块替代YOLO11的C3k2

会AI的学姐 293

1021.Deepest Root (25)

1021.Deepest Root (25)pat-al-10212017-02-04 考点:深搜dfs 关于连通分量的计算:从任一点出发开始深搜,结束一次搜索后如果还有点没被访问到(即,可以进行多次搜索)说明连通分量不止一个,能进行几次搜索就有几个连通分量 关于题目要求的找最长的路径的起始点,参考了:1021. Deepest Root (25)-PAT甲级真题。个人理解:第一次出发开始搜索(不管

一剑钦安 423

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

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 ...

Duck_Duck_的博客 490

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

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...

weixin_43871669的博客 418

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

浙大PAT 1021. Deepest Root (25)

1021. Deepest Root (25) 时间限制 1500 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A graph which is connected and acyclic can b

凌风 5209

1021 Deepest Root (25 分)

Input Specification: Each input file contains one test case. For each case, the first line contains a positive integer N (≤10​4) which is the number of nodes, and hence the nodes are numbered from 1 t...

ostrich的博客 520

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 ro...

SourDumplings的博客 248

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 ...

weixin_42105789的博客 373

1021 Deepest Root (25分)

1 题目 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...

韩江雪de 小屋 443
上一篇: 1020. Tree Traversals (25)
下一篇: 1022. Digital Library (30)
AI记忆
AI记忆 优质创作者: 人工智能技术领域 优质创作者: 人工智能技术领域 领域专家: 算法与数据结构技术领域 领域专家: 算法与数据结构技术领域
博客等级 码龄19年 6685粉丝 429原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI记忆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值