P5157 [USACO18DEC]The Cow Gathering】的更多相关文章

首先考虑怎么check一个点是否能被最后一个删除. 可以这么建图,以这个点建有根树,边全部向上指,再加上剩下的有向边. 很明显,这里的一条边的定义就变成了只有删去这个点,才可以删去它指向的点. 因此,只需要建n次图暴力判断是否有环即可. 这样做是n^2的. 考虑加入一条边后,会产生什么影响. 发现这条边会导致一些点答案直接被钦定为零(这些点满足以它们为根一定会存在环) 设边为u---->v 具体分析一下,这些点是所有以v为根建有根树后,u子树内的所有点. 这个可以通过类似换根的分类讨论的方法来找…
Description: 给定一棵树,每次删去叶子,有m个限制,分别为(a,b)表示a需要比b先删,为每个点能否成为最后被删的点 Hint: \(n,m \le 10^5\) Solution: 手模后会发现一个十分不显然的规律: 若a比b先删,则a在以b为根的子树中的点,都不能最后删, 于是这样就转化为这个题了:https://www.cnblogs.com/list1/p/10497877.html 每次直接打个差分标记 这题还要判无解的情况(这谁想得到啊) #include <map>…
首先可以思考一下每次能删去的点有什么性质. 不难发现,每次能删去的点都是入度恰好为 \(1\) 的那些点(包括 \(a_i \rightarrow b_i\) 的有向边). 换句话说,每次能删去的点既要是树上的叶子节点,并且不会被任意一条有向边 \(a_i \rightarrow b_i\) 指向.那么再来思考一下每个点能否走后离开. 因为 \(i\) 号点只能最后离开,那么我们将 \(i\) 看作这课树的根(因为每次只能走叶子).你会发现如果 \(i\) 不能最后走当前仅当会存在一条路径(走有…
题目描述 Bessie正在计划一年一度的奶牛大集会,来自全国各地的奶牛将来参加这一次集会.当然,她会选择最方便的地点来举办这次集会.每个奶牛居住在 N(1<=N<=100,000) 个农场中的一个,这些农场由N-1条道路连接,并且从任意一个农场都能够到达另外一个农场.道路i连接农场A_i和B_i(1 <= A_i <=N; 1 <= B_i <= N),长度为L_i(1 <= L_i <= 1,000).集会可以在N个农场中的任意一个举行.另外,每个牛棚中居…
题目链接 先把\(1\)作为根求每个子树的\(size\),算出把\(1\)作为集会点的代价,不难发现把集会点移动到\(u\)的儿子\(v\)上后的代价为原代价-\(v\)的\(size\)*边权+(总的\(size\)-\(v\)的\(size\))*边权 #include<iostream> #include<cstring> #include<cstdio> #define int long long using namespace std; const int…
题目描述 Bessie is planning the annual Great Cow Gathering for cows all across the country and, of course, she would like to choose the most convenient location for the gathering to take place. Bessie正在计划一年一度的奶牛大集会,来自全国各地的奶牛将来参加这一次集会.当然,她会选择最方便的地点来举办这次集会…
题目描述 Bessie is planning the annual Great Cow Gathering for cows all across the country and, of course, she would like to choose the most convenient location for the gathering to take place. Each cow lives in one of N (1 <= N <= 100,000) different ba…
P2986 [USACO10MAR]伟大的奶牛聚集Great Cow Gat… 题目描述 Bessie is planning the annual Great Cow Gathering for cows all across the country and, of course, she would like to choose the most convenient location for the gathering to take place. Each cow lives in on…
题目描述 Bessie is planning the annual Great Cow Gathering for cows all across the country and, of course, she would like to choose the most convenient location for the gathering to take place. Bessie正在计划一年一度的奶牛大集会,来自全国各地的奶牛将来参加这一次集会.当然,她会选择最方便的地点来举办这次集会…
题目描述 Bessie is planning the annual Great Cow Gathering for cows all across the country and, of course, she would like to choose the most convenient location for the gathering to take place. Bessie正在计划一年一度的奶牛大集会,来自全国各地的奶牛将来参加这一次集会.当然,她会选择最方便的地点来举办这次集会…