【2017 Multi-University Training Contest - Team 10 】Monkeys
【链接】点击打开链接
【题意】
子至少与一只猴子相连。2<=k<=n<=1e5
【题解】
【错的次数】
【反思】
【代码】
/* */
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <cstdlib>
#include <cmath>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define ld long double
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rf(x) scnaf("%lf",&x)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
#define sz(x) ((int) x.size())
#define ld long double typedef pair<int, int> pii;
typedef pair<LL, LL> pll; //mt19937 myrand(time(0));
//int get_rand(int n){return myrand()%n + 1;}
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e5; namespace IO {
const int MX = 4e7;//随输入量改变
char buf[MX]; int c, sz;
void begin() {
c = 0;
sz = fread(buf, 1, MX, stdin);
}
inline bool read(int &t) {
while (c < sz && buf[c] != '-' && (buf[c] < '0' || buf[c] > '9')) c++;
if (c >= sz) return false;
bool flag = 0; if (buf[c] == '-') flag = 1, c++;
for (t = 0; c < sz && '0' <= buf[c] && buf[c] <= '9'; c++) t = t * 10 + buf[c] - '0';
if (flag) t = -t;
return true;
}
} int n, k,dp1[N+10],dp2[N+10];//放 不放
vector <int> g[N + 10]; void dfs(int x) {
dp1[x] = 1,dp2[x] = 0;
int len = g[x].size();
rep1(i,0,len-1){
int y = g[x][i];
dfs(y);
dp1[x]+=min(dp1[y],dp2[y]);
dp2[x]+=dp1[y];
}
} int main() {
//Open();
//Close();
int T;
IO::begin();
IO::read(T);
while (T--) {
IO::read(n), IO::read(k);
rep1(i,1,n) g[i].clear();
rep1(i, 1, n - 1) {
int x;
IO::read(x);
g[x].pb(i+1);
}
dfs(1);
int dui = min(dp1[1],dp2[1]);
int flag = k&1;
k/=2;
if (k <= dui){
oi(k + flag);puts("");
}else{
//k>dui
oi(dui + k*2 - dui*2 + flag);puts("");
}
}
return 0;
}
【2017 Multi-University Training Contest - Team 10 】Monkeys的更多相关文章
- 【2017 Multi-University Training Contest - Team 10】Schedule
[链接]http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1010&cid=767 [题意] 给一些区间,每台机器在这些区间 ...
- 【2017 Multi-University Training Contest - Team 2】TrickGCD
[Link]:http://acm.hdu.edu.cn/showproblem.php?pid=6053 [Description] 给你一个b数组,让你求一个a数组: 要求,该数组的每一位都小于等 ...
- 【2017 Multi-University Training Contest - Team 2】Maximum Sequence
[Link]:http://acm.hdu.edu.cn/showproblem.php?pid=6047 [Description] 给你一个数列a和一个数列b; 只告诉你a的前n项各是什么; 然后 ...
- 【2017 Multi-University Training Contest - Team 2】 Regular polygon
[Link]: [Description] 给你n个点整数点; 问你这n个点,能够组成多少个正多边形 [Solution] 整点只能构成正四边形. 则先把所有的边预处理出来; 枚举每某两条边为对角线的 ...
- 【2017 Multi-University Training Contest - Team 2】 Is Derek lying?
[Link]: [Description] 两个人都做了完全一样的n道选择题,每道题都只有'A','B','C' 三个选项,,每道题答对的话得1分,答错不得分也不扣分,告诉你两个人全部n道题各自选的是 ...
- 【2017 Multi-University Training Contest - Team 4】Time To Get Up
[Link]: [Description] [Solution] 把每个数字长什么样存到数组里就好;傻逼题. (直接输入每一行是什么样子更快,不要一个字符一个字符地输入) [NumberOf WA] ...
- 【2017 Multi-University Training Contest - Team 7】Hard challenge
[Link]:http://acm.hdu.edu.cn/showproblem.php?pid=6127 [Description] 平面上有n个点,每个点有一个价值,每两个点之间都有一条线段,定义 ...
- 【2017 Multi-University Training Contest - Team 7】Kolakoski
[Link]:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1011&cid=765 [Description] 有一种 ...
- 【2017 Multi-University Training Contest - Team 9】FFF at Valentine
[链接]http://acm.hdu.edu.cn/showproblem.php?pid=6165 [题意] 一张有向图,n个点,m条边,保证没有重边和自环.询问任意两个点能否满足任何一方能够到达另 ...
随机推荐
- selenium+python 安装使用
一.序言 selenium官网selenium简单教程selenium完整教程python基础教程 二.安装python3 https://www.python.org/downloads/relea ...
- CodeForcesGym 100502E Opening Ceremony
Opening Ceremony Time Limit: 5000ms Memory Limit: 524288KB This problem will be judged on CodeForces ...
- SGU 323 Aviamachinations
Aviamachinations Time Limit: 4500ms Memory Limit: 65536KB This problem will be judged on SGU. Origin ...
- 【Linux环境编程】获取网卡的实时网速
在windows以下.我们能够看到360或者是qq安全卫士的"安全球".上面显示实时的网速情况.那么在linux里面怎样获取网卡的实时网速?事实上原理非常easy,读取须要获取网速 ...
- Project Euler :Problem 54 Poker hands
In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the ...
- 变量get、set设置
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- ZJOI2005沼泽鳄鱼
矩阵优化dp ** 注意:矩阵乘法没有交换律 ** 思路:类比P2151hh去散步 代码特点在一维的答案矩阵 1.矩阵优化两点间方案数不必赘述 2.注意2,3,4可以办到以他们的lcm为周期,正是因为 ...
- MVC和MTV设计模式
1.MVC MVC最初是由施乐公司旗下的帕罗奥多研究中心中的一位研究人员给 smalltalk语言发明的一中软件设计模式. MVC概述:MVC全名是ModelViewController,是模型(mo ...
- WPF MVVM架构 EF、WCF、IOC 设计示例经典
概要 该演示项目利用WPF应用程序构建的MVVM架构示例, 运用了Unity容器接口注入, MVVM的经典设计, 后台利用的EF+WCF. 后台实现: 从数据库生成的emdx 结合上下文进行数据交互, ...
- zookeeper提供了什么
简单的说,zookeeper=文件系统+通知机制. 每个子目录项如 NameService 都被称作为 znode,和文件系统一样,我们能够自由的增加.删除znode,在一个znode下增加.删除子z ...