博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BZOJ 1602 USACO 2008 Oct. 牧场行走
阅读量:4626 次
发布时间:2019-06-09

本文共 904 字,大约阅读时间需要 3 分钟。

【题解】

  要求出树上两点间的距离,树上的边有边权,本来应该是个LCA。

  看他数据小,Xjb水过去了。。。其实也算是LCA吧,一个O(n)的LCA。。。

#include
#include
#define N (1010)#define rg register#define LL long longusing namespace std;int n,m,root,cnt,tot,dep[N],in[N],out[N],fa[N],last[N],a[N][N];LL ans=0;struct edge{ int to,pre,dis; }e[N<<1];inline int read(){ int k=0,f=1; char c=getchar(); while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar(); while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar(); return k*f;}inline void add(int x,int y,int z){e[++tot]=(edge){y,last[x],z}; last[x]=tot;}void dfs(int x,int father){ in[x]=++cnt; dep[x]=dep[father]+1; for(rg int i=last[x],to;i;i=e[i].pre) if((to=e[i].to)!=father) dfs(to,fa[to]=x); out[x]=++cnt;}inline bool IN(int x,int y){ if(in[y]<=in[x]&&out[x]<=out[y]) return 1; return 0;}int main(){ n=read(); m=read(); for(rg int i=1,u,v,dis;i

  

转载于:https://www.cnblogs.com/DriverLao/p/8401449.html

你可能感兴趣的文章
评论列表显示及排序,个人中心显示
查看>>
JavaWeb学习笔记总结 目录篇
查看>>
C#根据html生成PDF
查看>>
Neutron SDN 手动实现手册
查看>>
linux下core文件调试方法
查看>>
20个创意404错误页面设计的启示
查看>>
基础训练 芯片测试
查看>>
如何用命令将本地项目上传到git
查看>>
JavaScript 实现鼠标拖动元素
查看>>
js 模糊查询 (360接口)
查看>>
python+rabbitMQ实现生产者和消费者模式
查看>>
“模态”对话框和“后退”按钮
查看>>
关于javascript实现的网站页面侧边悬浮框"抖动"问题
查看>>
linux_命令格式和命令提示符
查看>>
Cocos2d-X-3.0之后的版本的环境搭建
查看>>
when case group by 的用法集合
查看>>
洛谷P1908 逆序对
查看>>
转义符
查看>>
poj 1019
查看>>
asp.net mvc上传文件
查看>>