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 ...
 
随机推荐
- urljoin
			
from urlparse import urljoin urljoin("http://www.asite.com/folder/currentpage.html", " ...
 - python正则表达式re模块详细介绍--转载
			
本模块提供了和Perl里的正则表达式类似的功能,不关是正则表达式本身还是被搜索的字符串,都可以是Unicode字符,这点不用担心,python会处理地和Ascii字符一样漂亮. 正则表达式使用反斜杆( ...
 - windows 网页打不开github网站
			
gitbub是外网,经常会遇到访问不了的问题,并且有时能访问也网速好慢. 解决这个问题的方法是 更改hosts文件,地址:C:\Windows\System32\Drivers\etc 我在hosts ...
 - Knight Probability in Chessboard
			
2018-07-14 09:57:59 问题描述: 问题求解: 本题本质上是个挺模板的题目.本质是一个求最后每个落点的数目,用总的数目来除有所可能生成的可能性.这种计数的问题可以使用动态规划来进行解决 ...
 - python-day20--正则表达式与re模块
			
1.通过re模块可以做一些关于正则的相关操作 2.正则表达式:做字符串匹配的规则 1)字符组:在同一个位置可能出现的各种字符组成了一个字符组,在正则表达式中用[ ]表示 [0-9][a-f][A-F] ...
 - Ubuntu解压缩zip,tar,tar.gz,tar.bz2文件命令
			
tar解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName .gz解压1:gunzip FileName.gz解压2:gzip -d FileN ...
 - linux--多进程进行文件拷贝
			
学习IO的时候,我们都曾经利用文件IO函数,标准IO函数都实现了对文件的拷贝, 对某一个文件进行拷贝时,我们可以考虑一下几种方式: a.单进程拷贝: 假设某一文件需要拷贝100字节,每一个时间片可以完 ...
 - Oracle 账户锁定问题解决办法
			
1 打开 SQL PLUS 2 登录数据库 3 输入 conn/as sysdba; 4 输入 alter user 数据库名 account unlock;
 - vs2012修改代码编辑区域的背景色
 - Visual Sudio 2012转换界面风格
			
点击“工具”--->"选项"--->“环境”--->“常规”将Color theme由你的“Light”改为“Dark”,即可成为黑色的界面