POJ 2114 - Boatherds】的更多相关文章

原题地址:http://poj.org/problem?id=2114 题目大意: 给定一棵点数为\(n~(n \le 10000)\)的无根树,路径上有权值,给出m组询问($m \le 100$),每组询问给出一个k,问树中是否存在长度为k的链.题目是多case 题目分析: 这是第二次写树分治,细节想清楚真的很重要啊...写了两天才写过,接下来说一说算法流程和需要注意的细节吧 首先读入.建图等等等等.. 然后是分治过程: 0.如果当前处理的这棵树的size很小了,调用暴力解决,否则继续执行(这…
链接:http://poj.org/problem?id=2114 题意: 求树上距离为k的点对数量: 思路: 点分治.. 实现代码: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define inf 0x7fffffff ; struct node{ int to,ne…
Boatherds     Description Boatherds Inc. is a sailing company operating in the country of Trabantustan and offering boat trips on Trabantian rivers. All the rivers originate somewhere in the mountains and on their way down to the lowlands they gradua…
求一棵树上是否存在路径长度为K的点对. POJ 1714求得是路径权值<=K的路径条数,这题只需要更改一下统计路径条数的函数即可,如果最终的路径条数大于零,则说明存在这样的路径. 刚开始我以为只要在分治过程中出现过长度为K的就算是找到了,其实不然,因为可能是相同子树里面的两个结点,这个结果显然是错误的. #include <cstdio> #include <cstring> #include <algorithm> #include <vector>…
Boatherds Time Limit: 2000MS Memory Limit: 65536K Description Boatherds Inc. is a sailing company operating in the country of Trabantustan and offering boat trips on Trabantian rivers. All the rivers originate somewhere in the mountains and on their…
还是利用点的分治的办法来做,统计的办法不一样了,我的做法是排序并且标记每个点属于哪颗子树. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=1e4+9; int head[maxn],lon,n,mm,m; struct { int next,to,w; }e[maxn<&l…
标题效果:鉴于一棵树,问有两点之间没有距离是k的. 数据的多组 思维:和IOI2011的Race喜欢.不是这么简单.阅读恶心,我是在主要功能的别人的在线副本. CODE: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 10010 #define INF 0x3f3f3f3f using namespace std; int p…
存在2点间距离==k 输出AYE 否则输出NAY #include<stdio.h> #include<string.h> #include<algorithm> #include<vector> using namespace std; #define MAXN 100010 int n,m; int cnt,ans,mi,root,k; int head[MAXN],mx[MAXN],size[MAXN]; bool vis[MAXN]; struct…
/* 啊啊啊啊啊啊啊本题证明一个问题,在实际应用中sort比qsort块 还有memset这类初始化能不加尽量别加,很浪费时间 原来的程序把qsort该成sort,去掉一个无用memset就a了时间不到一半 题意:和poj1741差不多,不过本题求的是dis[i]+dis[j]==dis[k]; */ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> usi…
思路: 点分治 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 10005 int n,k,xx,yy,first[N],next[N*2],v[N*2],w[N*2],tot; int f[N],size[N],vis[N],d[N],deep[N],root,sum,ans; void add(int x,i…