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 ...
随机推荐
- python 递增递减数列
def is_arithmetic(l): delta = l[] - l[] ): ] - l[index] == delta): return False return True print(is ...
- Jmeter工具做性能测试 常见的错误汇总
在Win机器上用Jmeter做性能测试,汇总下我自身遇到的错误和解决方案 java.net.BindException: Address already in use: JVM_Bind 原因分析:压 ...
- Java编程语言下 Selenium 驱动各个浏览器代码
这里采用的是Selenium3.7版本,首先介绍的是在Windows环境下运行的: 总结下注意事项: 1,设置各个浏览器的Driver路径 System.setProperty("" ...
- Redis<一> 数据结构:String
). set key value : 将字符串值 value 关联到 key .如果 key 已经持有其他值, SET 就覆写旧值,无视类型. ). get key : 返回 key 所关联的字符串值 ...
- Python - WebDriver 识别登录验证码
Python - WebDriver 识别登录验证码 没什么可说的直接上代码! #-*-coding:utf-8-*- # Time:2017/9/29 7:16 # Author:YangYangJ ...
- LeetCode--202--快乐数
问题描述: 编写一个算法来判断一个数是不是“快乐数”. 一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变 ...
- android--------验证码倒计时
在我们注册或者修改信息的时候,常会用到60s倒计时这个功能,写了这篇文章,大家共享一下: 效果图: 直接上代码: activity.java public class MainActivity ext ...
- Python基础--列表、元组
一.什么是列表.元组 序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推. Python有6个序列的内置类型,但最常见 ...
- zabbix3.0.4 配置邮件报警
试验环境: LAMP环境 (LNMP环境已经成功了,为了避免干扰,我另一台LAMP主机) ### 我在做实验之前,作了时间同步,不知道这个有木有影响,一起说一下吧! yum -y install nt ...
- OAF 标准的供应商管理员批准流程
标准供应商审批流程 oracle.apps.pos.onboard.webui.FlexRegApproverPGCO--初始化poplist LinkedList actionListText = ...