Distance on the tree】的更多相关文章

Distance in the Tree Time limit: 1.0 secondMemory limit: 64 MB A weighted tree is given. You must find the distance between two given nodes. Input The first line contains the number of nodes of the tree n (1 ≤ n ≤ 50000). The nodes are numbered from…
Distance on the tree https://nanti.jisuanke.com/t/38229 DSM(Data Structure Master) once learned about tree when he was preparing for NOIP(National Olympiad in Informatics in Provinces) in Senior High School. So when in Data Structure Class in College…
Distance on the tree 题目链接 https://nanti.jisuanke.com/t/38229 Describe DSM(Data Structure Master) once learned about tree when he was preparing for NOIP(National Olympiad in Informatics in Provinces) in Senior High School. So when in Data Structure Cl…
Distance on the tree 题目链接 https://nanti.jisuanke.com/t/38229 Describe DSM(Data Structure Master) once learned about tree when he was preparing for NOIP(National Olympiad in Informatics in Provinces) in Senior High School. So when in Data Structure Cl…
传送门 题意: 给出一棵树,每条边都有权值: 给出 m 次询问,每次询问有三个参数 u,v,w ,求节点 u 与节点 v 之间权值 ≤ w 的路径个数: 题解: 昨天再打比赛的时候,中途,凯少和我说,这道题,一眼看去,就是树链剖分,然鹅,太久没写树链剖分的我一时也木有思路: 今天上午把树链剖分温习了一遍,做了个模板题: 下午再想了一下这道题,思路喷涌而出............ 首先,介绍一下相关变量: int fa[maxn];//fa[u]:u的父节点 int son[maxn];//son…
题目链接:https://nanti.jisuanke.com/t/38229 题目大意:给你n个点,n-1条边,然后是m次询问,每一次询问给你u,v,w然后问你从u -> v 的路径上有多少边是小于等于w的. AC代码: #include<iostream> #include<cmath> #include<stack> #include<queue> #include<stdio.h> #include<string> #i…
https://nanti.jisuanke.com/t/38229 题目: 给一颗树,m次查询ui->vi这条链中边权小于等于ki的边数. #include <bits/stdc++.h> #define mid (l+r>>1) #define lson (o<<1) #define rson (o<<1|1) #define all(x) (x).begin(),(x).end() using namespace std; ; vector<…
1000ms 262144K   DSM(Data Structure Master) once learned about tree when he was preparing for NOIP(National Olympiad in Informatics in Provinces) in Senior High School. So when in Data Structure Class in College, he is always absent-minded about what…
边权转点权,每次遍历到下一个点,把走个这条边的权值加入主席树中即可. #include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> using namespace std; ; struct node{ int l,r,cnt; }tree[maxx*]; int head[maxx],rk[maxx],siz[maxx],top[maxx],son[maxx],d[m…
T1题面: 输入点数为N一棵树 求树上长度恰好为K的路径个数 (n < 1e5, k < 500) 这是今天的考试题,也是一道假的紫题,因为我一个根本不会dp的蒟蒻只知道状态就一遍A掉了--(然后我当时不会--emm) 考虑f[i][j]表示点i为根的子树中深度为j的点的个数,初始设置f[i][0] = 1.转移的时候,每搞完一棵子树就用这棵子树内的数据用乘法原理更新ans,然后再把它的贡献累加给根,这样可以保证统计不重不漏. 也可以用点分治来做. 代码: #include <iostr…