ural1471 Distance in 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…
学了差不多一星期的主席树+树链剖分,再来看这题发现其实是个板子题 一开始想复杂了,以为要用类似求树上第k大的树上差分思想来解决这道题,但其实树链上<=k的元素个数其实直接可以用树链剖分来求 具体是把每条树链放到主席树上询问一下求和就好了 #include<bits/stdc++.h> using namespace std; #define maxn 100006 ]; int b[maxn],n,m,a[maxn],head[maxn],tot; ,;} void addedge(in…
最裸的点分治+fft,调了好久,太菜了.... #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; typedef long long ll; ,inf=1e9; ); int f[maxn],t,last[maxn],pre[maxn],other[maxn],siz[maxn…
题意 给一颗树,每条边有边权,每次询问\(u\)到\(v\)的路径中有多少边的边权小于等于\(k​\) 分析 在树的每个点上建\(1​\)到\(i​\)的权值线段树,查询的时候同时跑\(u,v,lca(u,v)​\)三个版本的线段树,查询\(1​\)到\(k​\)的树上差分和\(val[u]+val[v]-2*val[lca]​\) Code #include<bits/stdc++.h> #define fi first #define se second #define pb push_b…
贴贴大佬的计蒜客题解: The Preliminary Contest for ICPC China Nanchang National Invitational and International Silk-Road Programming Contest 离线处理,运用树链剖分让LCA跑快点 关键是把n-1条边,和m条询问边存起来 然后按边权值W进行升序: 这样在计数询问的时候我们从小到大计数: 每条边只会被记一次且从小到大,这样就不用担心当前计数会受上一计数更新时的影响: 每次把小于等于当…
题意:给出一棵树,给出每条边的权值,现在给出m个询问,要你每次输出u~v的最短路径中,边权 <= k 的边有几条 思路:当时网络赛的时候没学过主席树,现在补上.先树上建主席树,然后把边权交给子节点,然后数量就变成了 u + v - lca * 2.专题里那道算点权的应该算原题吧.1A = =,强行做模板题提高自信. 代码: #include<cmath> #include<set> #include<map> #include<queue> #incl…
Description Xenia the programmer has a tree consisting of n nodes. We will consider the tree nodes indexed from 1 to n. We will also consider the first node to be initially painted red, and the other nodes — to be painted blue. The distance between t…
Distance on the tree 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…
完了,这次做扯了,做的时候有点发烧,居然只做出来一道题,差点被绿. My submissions     # When Who Problem Lang Verdict Time Memory 4434550 Sep 9, 2013 11:57:20 AM OIer E - Xenia and Tree GNU C++ Accepted 842 ms 4260 KB 4434547 Sep 9, 2013 11:56:11 AM OIer E - Xenia and Tree GNU C++ W…
CodeForces Round 199 Div2   完了,这次做扯了,做的时候有点发烧,居然只做出来一道题,差点被绿. My submissions     # When Who Problem Lang Verdict Time Memory 4434550 Sep 9, 2013 11:57:20 AM OIer E - Xenia and Tree GNU C++ Accepted 842 ms 4260 KB 4434547 Sep 9, 2013 11:56:11 AM OIer…
In a row of trees, the i-th tree produces fruit with type tree[i]. You start at any tree of your choice, then repeatedly perform the following steps: Add one piece of fruit from this tree to your baskets.  If you cannot, stop. Move to the next tree t…
I. Max answer 链接:https://nanti.jisuanke.com/t/38228 思路: 枚举最小值,单调栈确定最小值的边界,用线段树+前缀和维护最小值的左右区间 实现代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 ; const ll inf = 1e9;…
打网络赛 比赛前的准备工作要做好 确保 c++/java/python的编译器能用 打好模板,放在桌面 A. PERFECT NUMBER PROBLEM #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <algorithm> #include <set> #include…
The Preliminary Contest for ICPC China Nanchang National Invitational 题目一览表 考察知识点 I. Max answer 单调栈+暴力?? J. Distance on the tree 树链剖分 M. Subsequence 思维??…
Prim 设图G=(V,E)是一个具有n个顶点的连通网,其生成树的顶点集合为U.首先把v0放入U,再在所有的u∈U,v∈V-U的边(u,v)∈E中找一条最小权值的边,加入生成树,并把该边的v加入U集合.如果U集合已经有n个元素,则结束,否则在剩下的部分中继续寻找最小权值的边. #include<stdio.h> #include<stdlib.h> #define infinity 9999 #define MAX 20 int G[MAX][MAX],spanning[MAX][…
Convex Fence I have a land consisting of n trees. Since the trees are favorites to cows, I have a big problem saving them. So, I have planned to make a fence around the trees. I want the fence to be convex (curves are allowed) and the minimum distanc…
距离B - Distance in the Tree 还是普通的LCA但是要求的是两个节点之间的距离,学到了一些 一开始我想用带权并查集进行优化,但是LCA合并的过程晚于离线计算的过程,所以路径长度会有所偏差 所以失败告终 网上查询之后懂得要提前进行一下预处理,在输入完全部的边之后,也就是数形成之后,计算dis——>也就是每个点到树根的长度 之后进行询问查询时:u,v 和 rt 这样uv的距离就是dis[u] + dis[v] - 2 * dis[rt]很好理解 时间复杂度也还可以 #inclu…
他和她 Time Limit: 2000/1000ms (Java/Others) Problem Description: 大二上学期刚过完,平时成绩不错的小V参加了一个小型编程比赛,遇到一道题,虽然是书上的却不会做.于是找了在机房的他帮忙. 他:什么题目这么厉害,书上有却不会? 小V:就是给若干个城市编号,也告诉了我连接这些城市的公路的距离,也有一些城市间是没有直接的路的.求从一个城市到另外一个城市的最短距离. 他:这不很简单的单向最短路径么?照书敲都行啦. 小V:不是什么比赛都能带书. 他…
解题过程 中午吃饭比较晚,到机房lfw开始发各队的账号密码,byf开始读D题,shl电脑卡的要死,启动中...然后听到谁说A题过了好多,然后shl让blf读A题,A题blf一下就A了.然后lfw读完M题(shl的电脑终于打开了,然后输入密码,密码错误...自闭),说AC 自动机板题,然后找板子,,,突然发现自己读错题目.后来不知道怎么A的.shl copy了一遍密码终于登上账号.然后lfw一个人用单调栈和前缀和st表A掉了I题:byf 秒了H题: shl和byf读j题,读完吧题意告诉lfw,lf…
目录 Contest Info Solutions A. PERFECT NUMBER PROBLEM D. Match Stick Game G. tsy's number H. Coloring Game' I. Max answer J. Distance on the tree K. MORE XOR M. Subsequence Contest Info Practice Link Solved A B C D E F G H I J K L M 8/13 O - - O - - O…
题目链接: http://codeforces.com/contest/161/problem/D D. Distance in Tree time limit per test 3 secondsmemory limit per test 512 megabytes 问题描述 A tree is a connected graph that doesn't contain any cycles. The distance between two vertices of a tree is th…