NBUT 1218 You are my brother 2010辽宁省赛
Time limit 1000 ms
Memory limit 131072 kB
Little A gets to know a new friend, Little B, recently. One day, they realize that they are family 500 years ago. Now, Little A wants to know whether Little B is his elder, younger or brother.
Input
For each test case, the first line has a single integer, n (n<=1000). The next n lines have two integers a and b (1<=a,b<=2000) each, indicating b is the father of a. One person has exactly one father, of course. Little A is numbered 1 and Little B is numbered 2.
Proceed to the end of file.
Output
Sample Input
5
1 3
2 4
3 5
4 6
5 6
6
1 3
2 4
3 5
4 6
5 7
6 7
Sample Output
You are my elder
You are my brother 签到题,树的基本概念,代码如下:
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<string>
using namespace std;
int n,t;
int fa[];
int x,y;
int main()
{
while(~scanf("%d",&n))
{
memset(fa,,sizeof(fa));
for(int i=;i<=n;i++)
{
scanf("%d%d",&x,&y);
fa[x]=y;
}
int la=,lb=;
int k=;
while(fa[k]!=k)
{
la++;
k=fa[k];
}
k=;
while(fa[k]!=k)
{
lb++;
k=fa[k];
}
if (la==lb) printf("You are my brother\n");
else
if (lb>la) printf("You are my younger\n");
else
if (lb<la) printf("You are my elder\n");
}
return ;
}
NBUT 1218 You are my brother 2010辽宁省赛的更多相关文章
- NBUT 1225 NEW RDSP MODE I 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Little A has became fascinated with the game Dota recent ...
- NBUT 1218 You are my brother
$dfs$. 记录一下每一个节点的深度就可以了. #include<cstdio> #include<cstring> #include<cmath> #inclu ...
- NBUT 1221 Intermediary 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB It is widely known that any two strangers can get to know ...
- NBUT 1224 Happiness Hotel 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB The life of Little A is good, and, he managed to get enoug ...
- NBUT 1222 English Game 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB This English game is a simple English words connection gam ...
- NBUT 1220 SPY 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB The National Intelligence Council of X Nation receives a ...
- NBUT 1219 Time 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Digital clock use 4 digits to express time, each digit ...
- NBUT 1223 Friends number 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Paula and Tai are couple. There are many stories betwee ...
- NBUT 1217 Dinner 2010辽宁省赛
Time limit 1000 ms Memory limit 32768 kB Little A is one member of ACM team. He had just won the g ...
随机推荐
- java工程师
java工程师 职位描述 1.参与产品后台需求和产品经理确定: 2.主导产品后台架构设计和前端通讯协议: 3.设计后台的架构,能支持大的并发量: 4.优化后台的性能,能保证接口的流畅性: 5.负责解决 ...
- ASP.NET MVC 中使用Ckeditor4.5 编辑器
一.在项目中添加Ckeditor4.5.11 (1) 新建 ASP.NET MVC5项目,解压缩ckeditor_4.5.11_standard.zip,在VS2015的解决方案资源管理器中将得到的“ ...
- 关于iBatis配置xml文件时出现中文注释出错的一个问题(很坑爹.)
才开始我没有使用SqlMap.properties来配置连接信息.所以直接用ctrl + shift + C然后往里面添加的中文注释 例: <!-- 注释--> 运行的时候报: Error ...
- bnu 51636 Squared Permutation 线段树
Squared Permutation Time Limit: 6000ms Memory Limit: 262144KB 64-bit integer IO format: %lld Ja ...
- Cocos2d-x学习笔记(九)场景切换
这里只介绍两个简单的两个场景相互切换的方法. void pushScene(Scene *sn)和void popScene(Scene *sn)是一对.前者将当前场景放入到场景堆栈中,并切换到下一个 ...
- c++ 判断数组元素是否有负数(any_of)
#include <iostream> // std::cout #include <algorithm> // std::any_of #include <array& ...
- Jmeter工具做性能测试 常见的错误汇总
在Win机器上用Jmeter做性能测试,汇总下我自身遇到的错误和解决方案 java.net.BindException: Address already in use: JVM_Bind 原因分析:压 ...
- spring事务管理方式大全
http://blog.csdn.net/baibinboss/article/details/64922472
- SQL Timeout超时的处理方法
第一步:修改Web.config配置文件.在数据库连接字符串中加上连接时间Connect Timeout,根据实际情况定时间. <!--连接数据库--> <connectionStr ...
- 16S 基础知识、分析工具和分析流程详解
工作中有个真理:如果你连自己所做的工作的来龙去脉都讲不清楚,那你是绝对不可能把这份工作做好的. 这适用于任何行业.如果你支支吾吾,讲不清楚,那么说难听点,你在混日子,没有静下心来工作. 检验标准:随时 ...