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
查看全文
相关阅读:
QT *.pri 语法学习
qt 的相对路径说法
openwrt 时间更新
openwrt network 初始化
在线配置热加载配置 go-kratos.dev 监听key 通过atomic.Value支持自动热加载
Monkey patching
UDP flood UDP Port Denial-of-Service Attack
一例 Go 编译器代码优化 bug 定位和修复解析
t
golang 网络编程之如何正确关闭tcp连接以及管理它的生命周期 socket
原文地址:https://www.cnblogs.com/Peter0701/p/11728629.html
最新文章
【Liunx】docker容器
【Liunx】前后端项目分离部署
【Liunx】django项目部署
【Liunx】MySQL安装主从复制
【Liunx】nginx代理
Python使用PIL模块生成随机验证码
Django之forms组件
Django与Ajax
Django之模型层-多表操作
Django之模型层-单表操作
热门文章
Django之模型层-了解ORM
Django之模板层-继承
Django之模板层-自定义过滤器以及标签
Django之模版层-语法:标签 {% %}
Django之模板层-语法:{{ }}
C++ 继承父类的构造函数
C++类中const函数与非const函数的调用规则
linux 桌面 开机自启动
linux qt 可执行文件打包
QT *pro文件的复制功能
Copyright © 2011-2022 走看看