zoukankan
html css js c++ java
最近公共祖先模板(未完待续)
最近公共祖先题目(持续更新)
(1.)
(Distance)
(Query)
(2.)
求和
倍增法求最近公共祖先
$View$ $Code$
```cpp #include
using namespace std; inline int read() { int ret=0,f=1; char ch=getchar(); while(ch>'9'||ch<'0') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { ret=(ret<<1)+(ret<<3)+ch-'0'; ch=getchar(); } return ret*f; } int n,m,s,t,x,y; int f[500005][20],d[500005]; int num,head[1000005]; queue
q; struct edge { int ver,nxt; }e[1000005]; inline void adde(int u,int v) { e[++num].ver=v; e[num].nxt=head[u]; head[u]=num; } inline void bfs() { d[s]=1; q.push(s); while(!q.empty()) { int x=q.front(); q.pop(); for(register int i=head[x];i;i=e[i].nxt) { int y=e[i].ver; if(d[y]) continue; d[y]=d[x]+1; f[y][0]=x; for(register int j=1;j<=t;j++) f[y][j]=f[f[y][j-1]][j-1]; q.push(y); } } } inline int lca(int x,int y) { if(d[x]
=0;i--) if(d[f[x][i]]>=d[y]) x=f[x][i]; if(x==y) return y; for(register int i=t;i>=0;i--) { if(f[x][i]!=f[y][i]) { x=f[x][i]; y=f[y][i]; } } return f[x][0]; } int main() { n=read(); m=read(); s=read(); t=(int)(log(n)/log(2))+1; for(register int i=1;i
查看全文
相关阅读:
RabbitMQ资料
在网页打开本地程序的思路
HttpClient的巨坑
webbrowser设置为相应的IE版本
cpupower:Shows and sets processor power related values
golang 国内环境配置
OSX 创建 randisk(或称 tmpfs)
Gentoo 搭遗
ubuntu 去除开机背景
fabric && cita 调研对比
原文地址:https://www.cnblogs.com/Peter0701/p/11728629.html
最新文章
Android 判断当前thread 是否是UI thread
Android Handler 的使用
BroPHP使用心得
移动开发方式的讨论
IP_MULTICAST_LOOP
绑定IP 绑定设备
STM32 CAN
ARM CORTEX-M3的时钟
stm8l定时器中的ARPE
如何设置路由器的MTU
热门文章
VLAN
指定PING的网卡
STM32定时器的两个小难点
windows枚举串口
ilasm修改源码
性能优化的最一般手段
CentOS7安装vncserver
The clickjacking attack
minikube start 使用Hyper-V
博客地址
Copyright © 2011-2022 走看看