Pet--hdu4707
Pet
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1809 Accepted Submission(s): 874
10 2
0 1
0 2
0 3
1 4
1 5
2 6
3 7
4 8
6 9
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100100
using namespace std;
int p[maxn],a,b;
void init()
{
int i;
for(i=;i<a;i++)
p[i]=i;
}
int find(int x)
{
int t=x;
while(t!=p[t])//不用压缩路径
t=p[t];
return t;
}
int fun(int x)
{
int i=x,num=;
while(i!=p[i])
{
//p[i]=find(i);//查找x的深度
i=p[i];
num++;
}
return num;
} int main()
{
int N,n,i,x,y,cot;
scanf("%d",&N);
while(N--)
{ cot=;
scanf("%d%d",&a,&b);
init();
for(i=;i<a-;i++)
{
scanf("%d%d",&x,&y);
p[y]=x;
}
for(i=a-;i>=;i--)
{
if(find(i)==)
if(fun(i)>b)
cot++;
}
printf("%d\n",cot);
}
return ;
}
Pet--hdu4707的更多相关文章
- HDU4707:Pet(DFS)
Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He ...
- hdu4707 Pet
Pet Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissio ...
- UAT SIT QAS DEV PET
UAT: User Acceptance Testing 用户验收测试SIT: System Integration Testing 系统集成测试PET: Performance Evaluation ...
- get a new level 25 battle pet in about an hour
If you have 2 level 25 pets and any level 1 pet, obviously start with him in your lineup. Defeat all ...
- hduoj 4707 Pet 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4707 Pet Time Limit: 4000/2000 MS (Java/Others) Memory ...
- HDU 4707:Pet
Pet Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- Microsoft .NET Pet Shop 4
Microsoft .NET Pet Shop 4:将 ASP.NET 1.1 应用程序迁移到 2.0 299(共 313)对本文的评价是有帮助 - 评价此主题 发布日期 : 2006-5-9 | 更 ...
- Pet
Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He ...
- asp.net的3个经典范例(ASP.NET Starter Kit ,Duwamish,NET Pet Shop)学习资料
asp.net的3个经典范例(ASP.NET Starter Kit ,Duwamish,NET Pet Shop)学习资料 NET Pet Shop .NET Pet Shop是一个电子商务的实例, ...
- Pet(hdu 4707 BFS)
Pet Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- 【Python网络编程】多线程聊天软件程序
课程设计的时候制作的多线程聊天软件程序 基于python3.4.3 import socket import pickle import threading import tkinter import ...
- Red and Black(poj 1979 bfs)
Red and Black Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 27891 Accepted: 15142 D ...
- load average[zhuan]
load average值的含义 单核处理器 假设我们的系统是单CPU单内核的,把它比喻成是一条单向马路,把CPU任务比作汽车.当车不多的时候,load <1:当车占满整个马路的时候 load= ...
- abiword Related Pages
Application Framework The 'af' directory contains all source code for the cross-platform application ...
- C# is 与 as 运算符
as运算符有一定的适用范围,它只适用于引用类型或可以为null的类型,而无法执行其他的转换,如值类型的转换以及用户自定义的类型转换,这类转换应该适用强制转换表达式来执行.as当转换不了的时候返回nul ...
- C# 字符串驻留池
在.Net中,对于相同的字符串,.Net会将它们指向同一个地址,它们是相同的实例..Net中的字符串并不会更新,当更改一个字符串变量时,由于字符串的不可变性,.Net实际上是新创建一个字符串,而将变量 ...
- 安装 Kali Linux 后需要做的 20 件事
安装 Kali Linux 后需要做的 20 件事 本文含有我觉得有用的每一件事情.本文分为三大部分: 专门针对Kali用户 Kali Linux是来自Debian的一个特殊版本,Kali Linux ...
- 携程SQL面试题忘大牛解答解决思路
讨论地址:http://bbs.csdn.net/topics/380208742
- UESTC_秋实大哥与妹纸 2015 UESTC Training for Data Structures<Problem F>
F - 秋实大哥与妹纸 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 1500/1500KB (Java/Others) Submit ...
- Pascal's Triangle II 解答
Question Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...