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
查看全文
相关阅读:
【Matlab系列】之基于元胞自动机的城市规划(程序修正)
【Bug】 Access Violation exception&First-chance exception
【Bug】缓冲区溢出检查_security_cookie
【PE】x264编解码器在Windows(MinGw环境)和Linux平台的编译过程以及使用方法
【C】printf()详解
【Linux】Linux下没有 itoa
【AVS】AVS2编码器开源啦:xAVS2
【OS】关于堆、栈生长方向和大小端模式
【PE/Python】python IDLE添加行号显示
【C】将数字转换为字符串的方法
原文地址:https://www.cnblogs.com/Peter0701/p/11728629.html
最新文章
Run Dashboard显示问题
【CV】虹膜识别源代码下载,分别基于MATLAB、C++、OpenCV
【matlab】Strel函数--结构元素
【Base】内存字节对齐
【mpeg4】xvid参数分析
【Tools】haneWIN NFS Server 1.2.10 注册机(亲测有效)
【Base】ping-pong buffer
【H.264 】open-GOP/close-GOP
【Complier】error C2275:将此类型用作表达式非法
【C99】restrict关键字
热门文章
【Complier】Makefile error make (e=2): The system cannot find the file specified
【x264】x264源码分析与应用示例——码率控制
【Base】固件,软件,硬件,驱动
【C/C++】函数调用协议__cdecl,__fastcall,__stdcall
【Hardware】STM32软件模拟IIC
【matlab】matlab中不用科学计数法显示结果
【VS】VS环境变量
【Bug】解决"应用程序配置不正确,程序无法启动"
【C++】关于堆栈的比较好的理解
【matlab】matlab2012a/2012b licence失效解决办法(循环注册)
Copyright © 2011-2022 走看看