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
查看全文
相关阅读:
lintcode 最长上升连续子序列 II(二维最长上升连续序列)
lintcode 滑动窗口的最大值(双端队列)
windows下实现Git在局域网使用
eclipse导入web项目之后项目中出现小红叉解决办法
HTTP协议基础
c++面试常用知识(sizeof计算类的大小,虚拟继承,重载,隐藏,覆盖)
Codeforces Round #327 (Div. 2) B. Rebranding C. Median Smoothing
c语言表白程序代码
矩阵的逆矩阵,伴随矩阵
document.getElementById()与 $()区别
原文地址:https://www.cnblogs.com/Peter0701/p/11728629.html
最新文章
Teradata 数据库介绍
管道的原子性 linux写操作原子性
使用 Valgrind 检测 C++ 内存泄漏
Valgrind
结构体的内存分配机制
十分钟快速入门 Python
旋转图像
lintcode 落单的数(位操作)
lintcode二叉树的锯齿形层次遍历 (双端队列)
c++ stringstream(老好用了)
热门文章
n个结点,不同形态的二叉树(数目+生成)
全排列总结
lintcode最长回文子串(Manacher算法)
java面试知识(来自牛客网)
lintcode循环数组之连续子数组求和
lintcode Permutation Index
windows8建立局域网的方法
c++堆
CSS中div覆盖另一个div
jsp通过易宝方式实现在线支付
Copyright © 2011-2022 走看看