题目链接 给一棵树, 每个节点有颜色, 两种操作, 一种是将一个节点的子树全都染色成c, 一种是查询一个节点的子树有多少个不同的颜色, c<=60. 每个节点一个bitset维护就可以. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include…
E. New Year Treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural…
题目链接 G. Yash And Trees time limit per test 4 seconds memory limit per test 512 megabytes input standard input output standard output Yash loves playing with trees and gets especially excited when they have something to do with prime numbers. On his 2…
POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根的编号永远是1.每个节点上最多结一个苹果.卡卡想要了解某一个子树上一共结了多少苹果. 现在的问题是不断会有新的苹果长出来,卡卡也随时可能摘掉一个苹果吃掉.你能帮助卡卡吗? 前缀技能 边表存储树 DFS时间戳 线段树 首先利用边表将树存储下来,然后DFS打上时间戳.打上时间戳之后,我们就知道书上节点对…
题目链接 题意: 一棵以1为根的树,树上每个节点有颜色标记(<=60),有两种操作: 1. 可以把某个节点的子树的节点(包括本身)都改成某种颜色 2. 查询某个节点的子树上(包括本身)有多少个不同的颜色 思路: 和2012年多校第7场的G题是同类题,DFS序处理出每个节点管辖的管辖范围[L[u], R[u]],其中L[u]就是子树根节点u所在的位置,用线段树成端更新颜色变化,注意到颜色(<=60),可以用bitset<60>,0表示没有这个颜色,1表示有,异或就能区间合并,最后co…
题目链接:点击传送 E. Propagating tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consi…
Apple Tree:http://poj.org/problem?id=3321 题意: 告诉你一棵树,每棵树开始每个点上都有一个苹果,有两种操作,一种是计算以x为根的树上有几个苹果,一种是转换x这个点上的苹果,就是有就去掉,没有就加上. 思路: 先对树求一遍dfs序,每个点保存一个l,r.l是最早到这个点的时间戳,r是这个点子树中的最大时间戳,这样就转化为区间问题,可以用树状数组,或线段树维护区间的和. #include <algorithm> #include <iterator&…
Apple Tree Time Limit: 2000MS   Memory Limit: 65536K       Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been carefully nurturing the big apple t…
E. Jamie and Tree time limit per test 2.5 seconds memory limit per test 256 megabytes input standard input output standard output To your surprise, Jamie is the final boss! Ehehehe. Jamie has given you a tree with n vertices, numbered from 1 to n. In…
PSHTTR: Pishty 和城堡题目描述 Pishty 是生活在胡斯特市的一个小男孩.胡斯特是胡克兰境内的一个古城,以其中世纪风格 的古堡和非常聪明的熊闻名全国. 胡斯特的镇城之宝是就是这么一座古堡,历史上胡斯特依靠这座古堡抵挡住了疯人国的大军. 对于 Pishty 来说,真正吸引他的是古堡悠长的走廊和高耸的钟楼,以及深藏于其中的秘密…… 古堡可以用一棵 N 个节点的树的描述,树中有 N −1 条无向边,每条边有一个魔法数字 C. 当一个旅游团参观古堡时,他们会选择树上 U 到 V 的路径游…