POJ 1986 LCA模板加强点的

Vc出现不能连接到一个或多个 vCenter server 系统:http://vcenter-vx.utibet.edu.cn:443/sdk 问题描述: 解决办法: esxi6.7的bug 第一种通过升级系统来解决问题 第二种是通过删除数据来解决 第一步:进入到esxi的shell 第二步查看其中的服务开启状态 第二步 df -h 第三步 /opt/vmware/vpostgres/current/bin/psql -d VCDB -U postgres 第四步 SELECT nspname || '.' || relname AS "relation", pg_size_pretty(pg_total_relation_size(C.oi 阅读详情

题意算是见过的最龌龊的了,你妹的,都不知道一共有多少个顶点,RE几次后立马把数组开到10W级别的;

#include<cstdio>
#include<string.h>
#include<algorithm>
#include<vector>
#include<stdlib.h>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<list>
using namespace std;
const int N=100015;
 struct node
 {
	 int u,next,w;
 }edge[N*2],Q[N];
 int father[N],dist[N],ance[N],head[N],st,et,qhead[N],res[N];
 bool flag[N],vis[N];
 int find(int x)
 {
  return x==father[x]?x:father[x]=find(father[x]);
 }
 void add(int u,int v,int val)
 {
	 edge[st].u=v;
	 edge[st].next=head[u];
	 edge[st].w=val;
	 head[u]=st++;
 }
 void Qadd(int u,int v,int i)
 {
	 Q[et].u=v;
	 Q[et].next=qhead[u];
	 Q[et].w=i;
	 qhead[u]=et++;
 }
 void dfs(int u,int  val)
 {    dist[u]=val;
     ance[u]=u;
      vis[u]=true;
  for(int i=head[u];i!=-1;i=edge[i].next)
   {
	  if(!vis[edge[i].u])
	  {
	    
		dfs(edge[i].u,edge[i].w+val);
	    father[find(edge[i].u)]=find(u);
	      ance[find(u)]=u;
	  }
   }
     flag[u]=true;
   for(int i=qhead[u];i!=-1;i=Q[i].next)
   {
	   if(flag[Q[i].u])
	   {
	     res[Q[i].w]=dist[u]+dist[Q[i].u]-2*dist[ance[find(Q[i].u)]];
	   }
   }
 }
 void init()
 {
	 st=0;
     et=0;
  memset(head,-1,sizeof(head));
  memset(qhead,-1,sizeof(qhead));
  memset(flag,false,sizeof(flag));
  memset(ance,0,sizeof(ance));
  memset(dist,0,sizeof(dist));
  memset(res,0,sizeof(res));
  memset(vis,false,sizeof(vis));
  
 }
 int main()
 {
	int n,k;
	while(~scanf("%d%d",&n,&k))
	{
		init();
	  for(int i=0;i<=n;i++)
	   {
	    father[i]=i;
	   }
	  int u,v,val;
	  char op[3];
	  while(k--)
	  {
	   scanf("%d %d %d %s",&u,&v,&val,op);
	   add(u,v,val);
	   add(v,u,val);
	  }
	  int t;
	  scanf("%d",&t);
	  for(int i=0;i<t;i++)
	  {
	   scanf("%d%d",&u,&v);
	   Qadd(u,v,i);
	   Qadd(v,u,i);
	  }
	  dfs(1,0);
	  for(int i=0;i<t;i++)
	  {
	   printf("%d\n",res[i]);
	  }
	}
 return 0;
 }


DeepSeek API调用太复杂?OneAPI一站式聚合解决方案 本文介绍了OneAPI如何作为一站式聚合解决方案,简化DeepSeek API的调用流程。通过统一接口、智能路由和模型映射等核心功能,OneAPI大幅降低了多API适配的复杂性,提升开发效率。文章还提供了详细的部署指南和高阶使用技巧,帮助开发者快速实现API聚合管理。 阅读详情

相关推荐

【STM32】基于STM32F103C8T6实现步进电机精准调速控制

本文详细介绍了如何使用STM32F103C8T6微控制器实现步进电机的精准调速控制。通过利用其内置定时器生成PWM脉冲,替代低效的延时方法,并结合TB6600驱动器进行硬件连接,可实现平滑、高效的电机速度控制。文章提供了基于HAL库的代码实战,包括速度与方向设置函数,并探讨了加减速规划等高级应用,帮助开发者彻底掌握步进电机驱动技术。

weixin_29169899的博客 486

LCA(最近公共祖先)倍增算法 通俗易懂Java

LCA最小公共祖先,Java语言实现,通俗易懂,新手必看

May_as_well的博客 2205

TAS5805MPWPR实战:数字音频功放从选型到量产全流程指南

数字音频功放将I2S数字信号直接转为PWM驱动扬声器,省去传统DAC与模拟运放链路,在高保真、低BOM与紧凑PCB之间找到平衡。其核心在于内置可编程DSP,支持多段PEQ、DRC等数字处理,通过I2C配置即可完成调音,而不占用主控算力。这类方案广泛应用于蓝牙音箱、Soundbar、智能音频模组等产品,但实际落地时常遇到I2C通信不稳定、EQ未生效、底噪超标、DC检测误触发等工程问题。从电源布局、LC滤波参数到PurePath Console工具链的使用,再到量产固件加载与故障排查,都需要系统化方法论支撑。本

weixin_29164843的博客 220

poj 1986

Distance Queries Time Limit:2000MS Memory Limit:30000K Total Submissions:8638 Accepted:3032 Case Time Limit:1000MS Description Farmer John's cows refused to r...

weixin_30917213的博客 182

软件测试 | 手把手教你如何使用 Charles 抓包工具(电脑+手机端)

软件测试 | 手把手教你如何使用 Charles 抓包工具(电脑+手机端)一、Charles简介二、Charles下载与安装三、Charles配置(1)Charles-PC端的配置如下:(2)过滤网络请求:(3)Charles抓取HTTPS请求包前置条件:(4)Charles抓取HTTPS双向认证包:关注我,免费领取学习资料 嘿。大家好,我是4U: 做过 APP 测试的同学都会接触抓包工具,通过抓包工具可以获取到客户端与服务端接口的交互数据,在实际测试APP的过程中,我们往往会发现服务端返回 的参数字段错

leboxy的博客 4154

小案例:利用图床自动化批量上传图片并获取图片链接

用python爬虫写了一个小脚本,用来自动上传图片到图床,然后返回链接,我们只需直接复制链接就可以。(需要安装Requests库) 因为不同图床需要提交的POST表单不一致,所以在这里我用ImgURL图床做示范,如果大家有需求,可自行修改代码。使用脚本的时候,我们只需把需要上传的图片和这个脚本放在同一个文件夹中,然后运行脚本,稍作等待,看到提示时就可以在脚本运行文件夹中发现一个名为“图片链接地址.txt”的文件,里面就是图片链接啦! 四、图片链接地址.txt(单张图片):...

采菊东篱下,Python满乾坤! 4413

POJ1986Distance Queries(双向带权LCA)

Farmer John's cows refused to run in his marathon since he chose a path much too long for their leisurely lifestyle. He therefore wants to find a path of a more reasonable length. The input to this pr

Lesroad 426

基于激光雷达的目标跟随功能移植到自己的ROS机器人小车上

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录前言一、下载目标跟随的源码二、修改话题名称1.修改/cmd_vel话题名称2.修改/scan话题名称3.修改双电机正反转4.目标跟随功能测试 前言 本人尝试把github上的一个目标跟随项目移植到自己的机器人小车上,并且成功了,最终小车可以跟着人移动,在这里分享一下心得。基于激光雷达的目标跟随,通过获取激光雷达的信息,跟随最近的物体。 提示:以下是本篇文章正文内容,下面案例可供参考 一、下载目标跟随的源码 源码地址:https:

weixin_44574633的博客 4463

poj 1986 lca板题

poj:1986 这两天学会了树上倍增求lca,感觉树上倍增在线求法好方便呀,而且很快,利用二进制拆分的思路和倍增思想,感觉挺不错,然后验了几道题感觉还不错,我写的板子解决一些题应该没什么大问题,学到新东西,心里怪开心的 AC代码: #include<cstdio> #include<cstring> #include<algorithm> using na...

yangzijiangac的博客 246

轴承故障诊断——领域知识

幅域分析、频域分析及轴承方面的领域知识

qq_58516607的博客 3535

FOFA奇技淫巧:从搜索语法到实战场景的深度挖掘

本文深入探讨了FOFA搜索语法在网络空间测绘中的高效应用,从基础语法到实战场景的深度挖掘。通过渗透测试、威胁狩猎、资产发现等实际案例,展示了如何利用FOFA精准定位目标系统、识别蜜罐、追踪威胁,并提供了合规使用指南和性能优化技巧,助力安全工作者提升效率。

weixin_32428571的博客 238

poj java 提交_POJ 1986 java代码实现

package pro.yao10_16LCA;import java.util.*;import java.io.*;/**7 61 6 13 E6 3 9 E3 5 7 S4 1 3 N2 4 20 W4 7 2 S31 61 42 6* @author XASW**/public class Main {static int T,N,Q,S,E,W,set[],vis[],D[],first...

weixin_35742852的博客 364

QNX侧触摸屏(TP)Bringup流程与源码深度解析

QNX侧TP Bringup的核心在于构建。

QQ_778132974的博客 478

POJ1986 Distance Queries (tarjan算法LCA 模板题)

题目 : http://poj.org/problem?id=1986 求最近公共祖先的tarjan 算法。 离线算法、时间复杂度为O(n) 基本框架 : 先用随便一种数据结构(链表就行),把关于某个点的所有询问标在节点上,保证遍历到一个点,能得到所有有关这个节点LCA 查询 建立并查集.注意:这个并查集只可以把叶子节点并到根节点,即getf(x)得到的总是x的祖先

Dewey's blog 931

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

POJ 1986 Distance Queries LCA

http://poj.org/problem?id=1986 Farmer John's cows refused to run in his marathon since he chose a path much too long for their leisurely lifestyle. He therefore wants to find a path of a more reasona...

xiji333的博客 230

深度学习工具包 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")

【POJ1986】Distance Queries-LCA算法

【POJ1986】Distance Queries-LCA算法

Maxwei_wzj的OI世界 405

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

【离线Tarjan 模板】LCA tarjan 算法 练习: hdu 2586 + poj 1986

个人一直觉得kuangbin大牛的LCA板子 感觉有点不太好用,于是在这个大牛的博客帮助下,更换了自己的板子; http://www.cnblogs.com/scau20110726/archive/2013/05/26/3100265.htmlhdu 2586, 给一颗树 ,每一条边有权值,然后m次询问,每一次询问两个点:i,j。 输出 i,j的最短距离。#include <iostream>

qq_24664053的博客 565

POJ1986,作为LCA模板

// Note:Your choice is C++ IDE #include #include #include #include using namespace std; const int mmax=100050; typedef struct sdlfj { int u,v,next,w; }Edge; typedef struct gf { int u,v,num; }Qu

zc850463390zc的专栏 650

【POJ1986】【模板】LCA

【模板】LCA

sdfzchy的博客 423

POJ_1986_Distance Queries(LCA+tarjan)

题意:在一棵树上,查询(u,v)最短距离。

一点也不二 938

POJ 1986(LCA and RMQ)

题意:给定一棵树,求任意两点之间的距离。 思路:由于树的特殊性,所以任意两点之间的路径是唯一的。u到v的距离等于dis(u) + dis(v) - 2 * dis(lca(u, v)); 其中dis(u)表示u到根节点的距离。 RMQ求LCA,过程如下,摘自http://dongxicheng.org/structure/lca-rmq/ 在线算法DFS+ST描述(思想是:将树...

dizhuo0219的博客 247

LCA

BB 众所周知,LCA有N种方法。一种种慢慢学。。。 方法 1. 倍增求法 2. 待续… Problem List POJ 1986 //POJ 1986 lca模板 #include<bits/stdc++.h> using namespace std; const int maxn=4e4+5; struct Edge{ int to; int len; }; vector...

Mr.chen116的博客 122

POJ1986-LCA问题的在线离线两种算法

在线算法:dfs+rmq /* 这个版本的在线算法比自创的好看简洁多了,可以当模板,效率不高在于算法其本身的原因; 据说离线算法要快不少。 */ #include #include #include #include #include using namespace std; const int NN=50000; int n,rt; vector > edge[NN]; i

Wo xi Meiz 4711

LCA问题

LCA(Least Common Ancestors),即最近公共祖先:在有根树中,找出某两个结点u和v最近的公共祖先(另一种说法,离树根最远的公共祖先)。        使用RMQ解决LCA问题,一篇不错的文档http://wenku.baidu.com/view/392c7023dd36a32d73758193.html,解释了两者之间的转换。 在线算法DFS+ST描述(思想是:将

新博客地址:sensirly.github.io 2139

LCA+poj1986

Language: Default Distance Queries Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 9081   Accepted: 3178 Case Time Limit: 1000MS Description Farme

龙崎的专栏 768

LCA模板在线 POJ 1986 Distance Queries

倍增LCA

NeighThorn的博客 399
上一篇: POJ1470&&最近公共祖先
下一篇: http://poj.org/problem?id=1657&&Distance on Chessboard
Java_beginer1
博客等级 码龄16年 22粉丝 84原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值