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
查看全文
相关阅读:
python os.path模块常用方法详解
PHP脚本执行效率性能检测之WebGrind的使用
Laravel操作上传文件的方法
Nginx获取自定义头部header的值
Laravel Nginx 除 `/` 外所有路由 404
laravel查看执行的sql语句
laravel 安装excel扩展
mysql 按值排序
处理laravel表单提交默认将空值转为null的问题
设置虚拟机里的Centos7的IP
原文地址:https://www.cnblogs.com/Peter0701/p/11728629.html
最新文章
angular-cli.json配置参数解析,常用命令解析
自定义网页右键菜单
input date
CDATA
网页中调整浏览器窗口大小
REACT Missing “key” prop for element
REACT map dictionary
cookie VS localstorage
用javascript切换bootstrap的tab
鼠标样式变为手指
热门文章
button中文字垂直居中
LeetCode之动态规划
linux命令详解2-文件管理,查看文件命令
linux查看电脑硬件配置
Django创建一个简单的blog
python+Django创建第一个项目
Python常见字符串处理操作
LeetCode之位操作题java
LeetCode之数组处理题java
LeetCode之字符串处理题java
Copyright © 2011-2022 走看看