题意: 树的根节点为水源,编号为 1 .给定编号为 2, 3, 4, …, n 的点的父节点.已知只有叶子节点都是房子. 有 q 个操作,每个操作可以是下列两者之一: + v ,表示编号为 v 的房子被歹徒占领. - v ,表示歹徒退出编号为 v 的房子. 初始所有房子都没有歹徒.对于每次变化后,要求删除最少的边,使得所有有歹徒的房子均无法与水源连通:同时,在此基础上要求受影响的普通房子数量最少. 题解: 首先对树的根节点的子树分类,那么实际上最多删除的边就是子树个数. 对于每个子树,如果要求受…
题意:现在有一棵树,1号节点是水源,叶子节点是村庄,现在有些怪兽会占领一些村庄(即只占领叶子节点),现在要割去一些边,使得怪兽到不了水源.给出怪兽占领和离开的情况,现在要割每次回答最小的割,使得怪兽不与1号节点有联系,而且满足被阻隔的村庄最少.输出最小割与组少的被误伤的村庄. 思路:把与一号节点相邻的点看作祖先gfa,然后它们自己作为树的根节点,根节点保存了子树里叶子节点的个数.很显然一棵树我们要割的是这棵树里所有怪兽的LCA与父亲边.子数里所有怪兽的LCA=LCA(最小DFS序的怪兽点,最大D…
C. Propagating tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/383/problem/C Description Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numb…
C. Propagating tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/383/problem/C Description Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numb…
http://codeforces.com/problemset/problem/570/D Tree Requests time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Roman planted a tree consisting of n vertices. Each vertex contains a lowercase…
链接 题解链接:点击打开链接 题意: 给定n个点的树.m个询问 以下n-1个数给出每一个点的父节点,1是root 每一个点有一个字母 以下n个小写字母给出每一个点的字母. 以下m行给出询问: 询问形如 (u, deep) 问u点的子树中,距离根的深度为deep的全部点的字母是否能在随意排列后组成回文串,能输出Yes. 思路:dfs序,给点又一次标号,dfs进入u点的时间戳记为l[u], 离开的时间戳记为r[u], 这样对于某个点u,他的子树节点相应区间都在区间 [l[u], r[u]]内. 把距…
参考九野巨巨的博客. 查询一个子树内的信息,可以通过DFS序转成线形的,从而用数据结构来维护. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <map> #define MP make_pair #define FI first #define SE second using namespace std; typedef…
D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive intege…
D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive intege…
The best programmers of Embezzland compete to develop a part of the project called "e-Government" — the system of automated statistic collecting and press analysis. We know that any of the k citizens can become a member of the Embezzland governm…