首页 > TAG信息列表 > Gardener

E. Gardener and Tree 拓扑排序板子

E. Gardener and Tree 将度为1的顶点加入队列,做拓扑排序,记录点的遍历层次,答案为 n-前k层的点   // AC one more times ////////////////////////////////////////INCLUDE////////////////////////////////////////// #include <iostream> #include <algorithm> #include <cst

codeforces-1593E -Gardener and Tree

codeforces-1593E -Gardener and Tree 题目大意: 有一颗无向边连接的树,每次操作剪掉所有的叶子节点。问k次操作后还剩下多少个节点。 思路和代码: ​ 说实话这个题目一拿到我就想把每个点的深度算出来,毕竟o(n)。但是越想越不对,这棵树妹有根啊!!没有根的树怎么做深搜找深度呢?搜了一篇

E. Gardener and Tree(拓扑)

Gardener and Tree 题意:k次操作,每次删去叶子节点,问最后剩的节点 思路:拓扑,度为1的就是叶子结点 //#pragma GCC optimize(2) //#pragma GCC optimize(3,"Ofast","inline") #include<bits/stdc++.h> #define int long long #define fi first #define se second #define pb push_

CF1593 E. Gardener and Tree(拓扑排序)

目录 Description State Input Output Solution Code Description 有一棵树,每次操作将叶子节点或根节点删除掉, \(k\) 此操作之后会剩下多少节点 State \(1<=t<=10^4\) \(1<=n<=4*10^5\) \(1<=k<=2*10^5\) Input 6 14 1 1 2 2 3 2 4 4 5 4 6 2 7 7 8 8 9 8 10 3 11 3 12