我太弱了,这叼题先搁着把,来日方长,自有切时。。。

。。。或许吧

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long
#define ON_DEBUG #ifdef ON_DEBUG #define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause") #else #define D_e_Line ; #endif struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std;
#include <vector> const int N = 300007; int n;
int ans[N]; struct Edge{
int nxt, pre, w;
}e[N << 1];
int head[N], cntEdge;
inline void add(int u, int v, int w){
e[++cntEdge] = (Edge){head[u], v, w}, head[u] = cntEdge;
} vector<int> G[N]; int dis[N]; int fa[N], son[N], dep[N], siz[N];
inline void DFS_First(int u, int father){
fa[u] = father, dep[u] = dep[father] + 1, siz[u] = 1;
for(register int i = head[u]; i; i = e[i].nxt){
int v = e[i].pre;
if(v == father) continue;
dis[v] = dis[u] + e[i].w;
DFS_First(v, u);
siz[u] += siz[v];
if(!son[u] || siz[v] > siz[son[u]]){
son[u] = v;
}
}
}
int dfn[N], dfnIdx, top[N];
inline void DFS_Second(int u, int ancester){
top[u] = ancester, dfn[u] = ++dfnIdx;
if(!son[u]) return;
DFS_Second(son[u], ancester);
for(register int i = head[u]; i; i = e[i].nxt){
int v = e[i].pre;
if(v != son[u] && v != fa[u]){
DFS_Second(v, v);
}
}
}
inline int LCA(int x, int y){
while(top[x] != top[y]){
if(dep[fa[top[x]]] < dep[top[y]]) Swap(x, y);
x = fa[top[x]];
}
return dep[x] < dep[y] ? x : y;
} int sta[N], _top;
inline void Insert(int x){
if(_top < 2){
sta[++_top] = x;
return;
}
int lca = LCA(x, sta[_top]);
if(lca == sta[_top]){
sta[++_top] = x;
return;
}
while(_top > 1 && dfn[sta[_top-1]] >= dfn[lca]){
G[sta[_top - 1]].push_back(sta[_top]);
-- _top;
}
if(lca != sta[_top]){
G[lca].push_back(sta[_top]);
sta[_top] = lca;
}
sta[++_top] = x;
} inline void DFS(){ } int a[N];
inline bool cmp(const int &a, const int &b){
return dfn[a] < dfn[b];
}
int main(){
io >> n;
R(i,2,n){
int u, v;
io >> u >> v;
add(u, v, 1);
add(v, u, 1);
} DFS_First(1, 0);
DFS_Second(1, 1); int Tasks;
io >> Tasks;
while(Tasks--){
int m;
io >> m;
R(i,1,m){
io >> a[i];
}
sort(a + 1, a + m + 1, cmp); R(i,1,m) Insert(a[i]);
while(_top > 1){
G[sta[_top - 1]].push_back(sta[_top]);
-- _top;
} DFS(1); R(i,1,m){
printf("%d ", ans[i]);
}
putchar('\n'); } return 0;
}

BZOJ3572/Luogu3233 [Hnoi2014]世界树 (虚树) (Unfinished)的更多相关文章

  1. 【BZOJ3572】[Hnoi2014]世界树 虚树

    [BZOJ3572][Hnoi2014]世界树 Description 世界树是一棵无比巨大的树,它伸出的枝干构成了整个世界.在这里,生存着各种各样的种族和生灵,他们共同信奉着绝对公正公平的女神艾莉森 ...

  2. bzoj3572[Hnoi2014] 世界树 虚树+dp+倍增

    [Hnoi2014]世界树 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 1921  Solved: 1019[Submit][Status][Dis ...

  3. bzoj 3572: [Hnoi2014]世界树 虚树 && AC500

    3572: [Hnoi2014]世界树 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 520  Solved: 300[Submit][Status] ...

  4. bzoj 3572: [Hnoi2014]世界树 虚树

    题目: Description 世界树是一棵无比巨大的树,它伸出的枝干构成了整个世界.在这里,生存着各种各样的种族和生灵,他们共同信奉着绝对公正公平的女神艾莉森,在他们的信条里,公平是使世界树能够生生 ...

  5. BZOJ 3572: [Hnoi2014]世界树 [虚树 DP 倍增]

    传送门 题意: 一棵树,多次询问,给出$m$个点,求有几个点到给定点最近 写了一晚上... 当然要建虚树了,但是怎么$DP$啊 大爷题解传送门 我们先求出到虚树上某个点最近的关键点 然后枚举所有的边$ ...

  6. bzoj 3572 [Hnoi2014]世界树——虚树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3572 关于虚树:https://www.cnblogs.com/zzqsblog/p/556 ...

  7. BZOJ 3572: [Hnoi2014]世界树 虚树 树形dp

    https://www.lydsy.com/JudgeOnline/problem.php?id=3572 http://hzwer.com/6804.html 写的时候参考了hzwer的代码,不会写 ...

  8. 【BZOJ】3572: [Hnoi2014]世界树 虚树+倍增

    [题意]给定n个点的树,m次询问,每次给定ki个特殊点,一个点会被最近的特殊点控制,询问每个特殊点控制多少点.n,m,Σki<=300000. [算法]虚树+倍增 [题解]★参考:thy_asd ...

  9. 洛谷 P3233 [HNOI2014]世界树(虚树+dp)

    题面 luogu 题解 数据范围已经告诉我们是虚树了,考虑如何在虚树上面\(dp\) 以下摘自hzwer博客: 构建虚树以后两遍dp处理出虚树上每个点最近的议事处 然后枚举虚树上每一条边,考虑其对两端 ...

随机推荐

  1. 理解RESTful Api设计

    REST REST(REpresentational State Transfer)是 Roy Fielding 博士于 2000 年在他的博士论文中提出来的一种软件架构风格(一组架构约束条件和原则) ...

  2. 关于『HTML5』第一弹

    关于『HTML5』:第一弹 建议缩放90%食用 祝各位国庆节快乐!!1 经过了「过时的 HTML」.「正当时的 Markdown」的双重洗礼后,我下定决心,好好学习HTML5  这回不过时了吧(其实和 ...

  3. nginx https证书配置

    1. Nginx配置 server { listen 443; #指定ssl监听端口 server_name www.example.com; ssl on; #开启ssl支持 ssl_certifi ...

  4. java编程用大小写字母及数字输出五位数验证码

    package day08; import java.util.Random;//导入util下的Random包 public class Yanzhengma { public static voi ...

  5. 六、LVM和从磁盘配额

    一.LVM概述 Logical Volume Manager,逻辑卷管理 优点:能够保证在现有数据不变的情况下,动态调整磁盘容量,从而提高磁盘管理的灵活性 /boot分区用于存放引导文件,不能基于LV ...

  6. 关于个人全栈项目【臻美IT】博客类出现的问题以及解决方法

    每做一个项目,要记得写下心得哦,别偷懒啊!先上网址:https://www.maomin.club/ 这个项目属于博客类的,因为百度审核的问题就大体做了下,就当来练练手,里面文章链接的是CSDN的博客 ...

  7. SprinigBoot自定义Starter

    自定义Starter 是什么 starter可以理解是一组封装好的依赖包,包含需要的组件和组件所需的依赖包,使得使用者不需要再关注组件的依赖问题 所以一个staerter包含 提供一个autoconf ...

  8. 获取mybatis注解方式新增数据时非自增插入的主键

    场景:插入数据的时候,获取不到非自增的主键.原因:对象中没有主键的值,插入后主键才有值. 解决方案:使用 @SelectKey @SelectKey中: statement是要运行的SQL语句,即查询 ...

  9. iNeuOS工业互联网操作系统,视图建模(WEB组态)增加2154个行业矢量图元、大屏背景及相关图元

     1.   概述 现在三维数字孪生(3D)比较流行,各行业各领域的项目也都在上数字孪生项目或是项目中包括数字孪生模块,能做的厂家也很多.从全厂区的应用视觉的冲击力还是比较震撼,但是数字孪生不太可能包括 ...

  10. 如何写好测试用例以及go单元测试工具testify简单介绍

    背景 ​ 最近在工作和业余开源贡献中,和单元测试接触的比较频繁.但是在这两个场景之下写出来的单元测试貌似不太一样,即便是同一个代码场景,今天写出来的单元测试和昨天写的也不是很一样,我感受到了对于单元测 ...