PAT 1021. Deepest Root

SAP特殊采购类80实战:跨工厂生产配置避坑指南(附完整测试流程) 本文深入解析SAP特殊采购类80在跨工厂生产场景下的实战应用与配置要点。文章从核心业务逻辑出发,详细拆解了后台配置、主数据与BOM的“双工厂”思维模式,并提供了从创建需求到成品收货的完整测试流程。重点揭示了多层BOM下的需求传递陷阱及常见报错解决方案,旨在帮助SAP顾问及用户规避实施风险,实现资源的灵活调度与流程自动化。 阅读详情

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1021

题解:

给N个点,N-1条边,先判断是否为树,如果不是树,输出有几块;如果是树,求符合条件的i是哪些(当第i个节点为树根时,树的高度最大)。

先用并查集求所给的是否为树,然后通过两次dfs求最长的树径,第二次dfs时就可以记录符合条件的i,最后结合第一次和第二次的结果,从小到大排序输出。

注:测试数据中有n=1的情况。

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
#define MAX 10005
int edge[MAX<<1];//表示第i条边的终点
int nextx[MAX<<1];//与第i条边同起点的下一条边的位置
int head[MAX<<1];//以i为起点的第一条边的储存位置
int pre[MAX];
bool visited[MAX];
int n;
int maxDeep;
int point;
set<int> q,out;
void insert(int i,int a,int b)//a起点,b终点
{
    edge[i]=b;
    nextx[i]=head[a];
    head[a]=i;
}
int Find(int x)//查找
{
    if(pre[x]==x) return x;
    return pre[x]=Find(pre[x]);
}
void Union(int a,int b)//合并
{
    int x=Find(a);
    int y=Find(b);
    if(x!=y)
        pre[y]=x;
}
void dfs(int st,int deep)
{
    if(deep>maxDeep)
    {
        maxDeep=deep;
        point=st;
        q.clear();
        q.insert(st);
    }
    else if(deep==maxDeep)
        q.insert(st);
    visited[st]=true;
    for(int i=head[st]; i!=-1; i=nextx[i])
    {
        if(visited[edge[i]]==false)
            dfs(edge[i],deep+1);
    }
    visited[st]=false;
}
int main()
{
    int a,b;
    int countx=0;
    set<int>::iterator iter;
    scanf("%d",&n);
    for(int i=0; i<=n; ++i)
        pre[i]=i;
    memset(nextx,-1,sizeof(nextx));
    memset(head,-1,sizeof(head));
    memset(edge,-1,sizeof(edge));
    for(int i=1; i<2*n-1; i+=2)
    {
        scanf("%d%d",&a,&b);
        Union(a,b);
        insert(i,a,b);
        insert(i+1,b,a);
    }
    for(int i=1; i<=n; ++i)
        if(pre[i]==i)
            ++countx;
    if(countx>1)
    {
        printf("Error: %d components\n",countx);
        return 0;
    }
    if(n==1)
    {
        printf("1\n");
        return 0;
    }
    memset(visited,false,sizeof(visited));
    maxDeep=0;
    dfs(1,0);
    memset(visited,false,sizeof(visited));
    for(iter=q.begin();iter!=q.end();++iter)
    {
        out.insert(*iter);
    }
    q.clear();
    maxDeep=0;
    a=point;
    dfs(point,0);
    for(iter=q.begin();iter!=q.end();++iter)
    {
        out.insert(*iter);
    }
    out.insert(a);
    for(iter=out.begin();iter!=out.end();++iter)
    {
        printf("%d\n",*iter);
    }
    return 0;
}

来源: http://blog.youkuaiyun.com/acm_ted/article/details/20146471

手把手教你用smarteye搭建免费GB28181监控平台(含海康设备接入避坑指南) 本文提供了一份基于SmartEye搭建免费GB28181视频监控平台的实战指南。详细介绍了从服务器部署、GB28181协议核心配置,到海康威视等主流设备接入的完整流程,并重点分享了设备注册失败、无法预览等常见问题的深度排错方法,旨在帮助中小企业及开发者低成本实现多品牌监控设备的统一管理。 阅读详情

相关推荐

Win本地部署DeepSeek

Ollama 提供了简单的接口,用于创建、运行和管理这些模型,同时还维护了一个丰富的预构建模型库,可以轻松集成到各种应用程序中。重启ollama,具体操作为打开搜索ollama进程,将其结束进程,之后再执行相关模型下载命令即可,或重启电脑!Ollama支持多种DeepSeek模型版本,用户可以根据硬件配置选择合适的模型。配置添加系统环境变量OLLAMA_MODELS,设置其值为新的路径,点击确定应用。安装完成后,在终端输入以下命令,检查Ollama版本。:14B、32B或70B版本,适合高端GPU。

m0_67297673的博客 2389

PAT1021(Deepest Root)

(参考树的直径的求法,两遍dfs) 虽然到节点1的最远节点有多个 但是只需要取其中一个来求其最远节点即可以 #include <bits/stdc++.h> using namespace std; #define fin freopen("in.txt", "r", stdin) #define fout freopen("out.txt", "w", stdout) const i...

love_wjk的博客 187

实战指南:轻松破解DataDome滑块验证码的关键步骤

本文详细介绍了破解DataDome滑块验证码的关键步骤,包括理解其工作原理、准备工作、参数获取与配置、完整破解流程及API调用。通过使用Capsolver服务和模拟真实用户行为,帮助开发者有效绕过这一反机器人机制,同时强调了法律与道德考量。

weixin_30415113的博客 480

PAT真题(C语言)——1021: Deepest Root

在写题目前先写一些自己的感想。 之前刷题一直是自己在楞刷题,倒是也解决了很多问题,可是没有形成一套有效的模板。其实写代码这个东西还是有套路的,什么时候该快排,什么时候该深度遍历,掌握了这个套路很多问题都能迎刃而解,尤其还是PTA这种套路还比较明显的题库。 这道题自己做的时候有两个测试点一直过不去,于是决定沉下心好好看看别人的,参考了《算法笔记》和网上大神的代码,发现自己真的还很不够。 之前一直不想...

weixin_43857778的博客 282

手把手教你用 Cursor 写一个完整的 Web 应用(含前后端 + 部署)

本文介绍如何利用Cursor AI工具从零开发一个完整的全栈待办事项Web应用。文章针对开发者常见痛点——无法独立完成项目闭环,提供了一套AI驱动的全栈开发范式。通过Vue3+Node.js+MySQL技术栈,全程由Cursor自动生成项目架构、前后端代码、数据库设计,并解决联调、部署等关键问题。重点展示了如何用AI完成:项目规划与架构设计、后端接口开发、前端页面实现、跨域联调、打包优化及云端部署全流程。该方法将传统需要3-5天的开发工作压缩至1小时内完成,产出规范可上线的项目,特别适合想突破"碎

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 633

Autosar 下电过程-基于ETAS工具

本文介绍基于ETAS工具对应的BIP包的下电过程,仅供参考。在最后调用SBC下电时,需要理清楚SBC的休眠流程,否则可能会出现休眠又唤醒情况。后面有空会介绍9471的休眠流程。

赞的博客 810

PAT 乙级 1021 (方法 + 代码)

1021 个位数统计 (15 分) 给定一个k位整数N = dk-110k-1 + … + d1101 + d0 (0&lt;=di&lt;=9, i=0,…,k-1, dk-1&gt;0),请编写程序统计每种不同的个位数字出现的次数。例如: 给定N = 100311,则有2个0,3个1,和1个3。 输入格式: 每个输入包含1个测试用例,即一个不超过1000位的正整数N。 输出格式: 对N中每一种...

SupremeBUCT的博客 383

CDDT CST CDDT CSTTT

This is the second part of the SA8653 automotive CDDT configuration guide. It describes the matching rules and modification methods between CDDT and device‑tree DDTS. It explains CDT’s underlying logic and configuration in TZ, QNX and Android. It details C

qq_39257814的博客 1410

PAT甲级真题1021 最深的根(网上题解最好懂)

一个无环连通图可以被视作一个树。 树的高度取决于所选取的根节点。 现在,你要找到可以使得树的高度最大的根节点。 它被称为最深的根。 输入格式 第一行包含整数 NN,表示节点数量。 节点编号为 1∼N1∼N。 接下来 N−1N−1 行,每行包含两个整数,表示两个节点之间存在一条边。 输出格式 输出最深的根的节点编号。 如果最深的根不唯一,则按照从小到大的顺序,将它们依次输出,每个占一行。 如果给定的图不是树,输出 Error: K components,其中 KK 是图中连通分量的数量。 数据范围 1≤N≤1

qq_43738331的博客 625

MFC 中实现 WebSocket 客户端以支持实时双向通信

3. **协议兼容**:若服务器使用 `wss://`(加密),需在 `lws_client_connect_info` 中配置 SSL 相关参数(`ssl_connection = LCCSCF_USE_SSL`)。- 编辑框(`m_editUrl`):输入 WebSocket 服务器地址(如 `ws://echo.websocket.events`)。2. 将编译后的库文件(`.lib`、`.dll`)和头文件路径添加到 MFC 项目中(项目属性 -> VC++ 目录)。// UI:服务器地址。

寒寒豆豆软件公司的博客 202

银河麒麟桌面系统批量交付:封装自动化ISO镜像,百台装机效率提升10倍

麒麟桌面系统自动化ISO镜像定制摘要 本文详细介绍麒麟桌面版ISO安装镜像的定制方法,通过修改系统文件实现自动化安装部署。主要内容包括:1) 挂载原版ISO并提取文件;2) 使用unsquashfs解压系统文件进行定制化修改,包括添加系统标记配置;3) 配置ky-installer.cfg自动应答文件,设置安装参数如用户名、密码、分区方案等;4) 修改grub引导配置启用自动安装模式。该流程支持磁盘加密、自定义分区、自动登录等功能,生成的定制镜像可满足批量部署需求,显著提升系统安装效率。

信创运维工程师 · 银河麒麟 & 容器实战 | 金融生产环境迁移·等保加固 | 142篇原创·17万+阅读 1506

pat 甲级 1021 Deepest Root

中文意思:一个无环连通图可以被视作一个树。树的高度取决于所选取的根节点。现在,你要找到可以使得树的高度最大的根节点。它被称为最深的根。

weixin_50671259的博客 1022

VI4302 1D dToF Sensor助力无人机定高避障:一场前所未有的飞行体验

另外,传感器因测量精度不够,产生的高度信息误差,会导致无人机无法精确定高,影响飞行稳定性和安全降落。芯视界于2022年发布的全新一代基于单光子探测技术的dToF激光雷达传感器芯片-VI4302,采用单电源低功耗系统,实现高性能测距、高稳定性,同时具备极强抗阳光能力以及兼容性等强大优势。无人机可以根据传感器提供的信息,快速调整飞行路径,避开潜在的障碍物,确保平稳的飞行。VI4302 1D dToF Sensor能够以极高的精度测量物体与无人机之间的距离,实现毫米级别的测量精度。⭐ 体型小巧,灵敏度高。

致力于lidar应用开发 621

PAT-1021 Deepest Root

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 Specification: Each i

weixin_42100456的博客 171

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

visio安装包

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

【PAT 甲级】1021 Deepest Root

1021 Deepest Root

AmiaYukiAchami的博客 703

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

【PAT1021】Deepest Root 代码记录

1. 第一次使用邻接矩阵,由于题目中的节点数为N,但是边数为N-1,所以矩阵稀疏,使得测试时测试点3内存超限 23分/25分 代码记录如下: //这里是一个稀疏矩阵 #include <iostream> #include <vector> #include <algorithm> #include <queue> using namespac...

qq_41035731的博客 240

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

[PAT-A 1021]Deepest Root

题目大意: 给出N个节点和N-1条边,问它们能否形成一颗N个节点的树,如果能,则从中选出节点作为树根,使得可以得到的树的高度最大 思路: 1.判断图是否联通,可以使用dfs或者并查集,每次读入一条边和两个端点,判断这两个端点是否属于相同的集合,即集合根节点是否相同,如果不同,将它们合并到一个集合中去,处理完之后判断产生集合的个数是否为1来判断给定的图是否联通。 2.当图联通时,由于题目保证只有N...

RegulusF的博客 209

PAT甲级 1021 Deepest Root

PAT甲级 1021 Deepest Root 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 hi...

旺崽的博客 2905

PAT 甲级 1021  Deepest Root

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

漫浸天空的雨色的备忘录~ 827

PAT-ADVANCED1021——Deepest Root

我的PAT-ADVANCED代码仓:https://github.com/617076674/PAT-ADVANCED 原题链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805482919673856 题目描述: 题目翻译: 1021 最深的根 一张无环连通图可以被看作是一棵树。树的高度取决于根节点的...

清风阁 268

PAT-A 1021. Deepest Root(搜索)

题目链接:https://www.patest.cn/contests/pat-a-practise/1021 题意:无环连通图也可以视为一棵树,选定图中任意一点作为根,如果这时候整个树的深度最大,该点称为 deepest root。 给定一个图,按升序输出所有 deepest root。如果给定的图有多个连通分量,则输出连通分量的数量。 要想树的深度最大,那么树跟一定是一个度为1的点

Benjamin_Z的博客 555

PAT 甲级 1021(Deepest Root )

PAT 甲级 1021题目要求翻译代码思路 题目要求 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_42865772的博客 471

PAT(Advanced)1021 Deepest Root (DFS)(并查集)(邻接表)C++实现

PAT(Advanced)甲级1021 Deepest Root (DFS)(并查集)(邻接表)C++实现 题目链接 PAT(Advanced)1021 题目大意 输入为无向无环图,任意顶点作为树根时能够达到树的最大深度的所有顶点(递增输出),同时,输入的图可能不连通,即无法构成一个树,此时输出该图树的数量(即根节点数目)。 AC代码 #include<bits/stdc++.h> u...

qq_44486439的博客 520

PAT 1021 Deepest Root

PAT 1021 Deepest Root 图的存储+dfs判断连通+dfs找树的深度

2301_80219163的博客 418

PAT-A1021 Deepest Root

PAT-A1021 Deepest Root 题目 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_41515197的博客 228

【PAT A1021】Deepest Root

思路 从每个节点依次构树,选最大者就好了(height数组记录每个节点所构树的高度),如果在构树的过程中有节点没有访问到,说明不连通,此时在没有访问的节点处再次dfs构树,依次下去即可得到连通分支个数。 #include <cstdio> #include <vector> #include <algorithm> using namespace std; ...

lvmy3的博客 239
上一篇: PAT 1061. Dating
下一篇: PAT 1069. The Black Hole of Numbers
ACM_Ted
博客等级 码龄15年 122粉丝 208原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值