#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #define N 40005 #define M 80005 #define LL long long using namespace std; const int INF = 0x3f3f3f3f; int ver[M],edge[M],head[N],Next[M]; int n,m,tot,r…
Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12276   Accepted: 3886 Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. Give an…
询问树上距离为k的点对是否存在 直接n^2暴力处理点对 桶排记录 可以过 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; ; ], nxt[MAXM << ], Head[MAXN], ed = ; ]; ]; inline void addedge(int u, int v, int c) { to[++ed] = v; cost[ed] = c;…
D. Distance in Tree time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard output A tree is a connected graph that doesn't contain any cycles. The distance between two vertices of a tree is the length (…
P3806 [模板]点分治1 题目背景 感谢hzwer的点分治互测. 题目描述 给定一棵有n个点的树 询问树上距离为k的点对是否存在. 输入格式 n,m 接下来n-1条边a,b,c描述a到b有一条长度为c的路径 接下来m行每行询问一个K 输出格式 对于每个K每行输出一个答案,存在输出“AYE”,否则输出”NAY”(不包含引号) 输入输出样例 输入 #1复制 2 1 1 2 2 2 输出 #1复制 AYE 说明/提示 对于30%的数据n<=100 对于60%的数据n<=1000,m<=50…
题目的大概意思现在有一棵树,在树上找半径小于等于2的最小覆盖点的最小个数. 题目链接 讲一讲此类题的贪心策略: 就是每次寻找最低没有被覆盖的点,显然对于覆盖它的所有点中,在他的祖先处设立一个点最优.所以在它的祖先处设一个点,然后ans++,并且更新它父节点和祖先对于点的距离. 然后如果半径更大的话,需要维护的就稍微多一些,要维护到上面的k位祖先,然后其他思路一致. #include<cstdio> #include<algorithm> #include<cstring>…
这题和poj 1741是一模一样的 但是1741能AC的代码,在这里却是TLE,暂时没看出哪里出现了问题.. AC代码: #include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack&g…
Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 24253   Accepted: 8060 Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. Give an…
题意是说给了n个点的树n<=10000,问有多少个点对例如(a,b)他们的之间的距离小于等于k 采用树的分治做 #include <iostream> #include <cstdio> #include <string.h> #include <algorithm> #include <vector> using namespace std; ; ],to[maxn*],numofE,dist[maxn*]; void add(int u…
POJ1741:Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 29574   Accepted: 9915 Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. …