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 ...
随机推荐
- ubuntu 14.04 安装redis5.0.3
redis下载地址:http://download.redis.io/releases/ 新建Redis目录,下载Redis 安装包: mkdir rediscd rediswget http://d ...
- sudo: /etc/sudoers is world writable sudo: no valid sudoers sources found, q...
今天操作/etc/sudoers 文件,因为该文件只读,所以sudo chmod 777 /etc/sudoers ,结果可以修改这个文件了,但是导致所有用户的sudo都不能用了 是因为在Linux中 ...
- [原]设置vs的release版本调试
通过三步设置就可以实现realse下的调试啦: 1.设置“C/C++”------>“常规”------->“调试信息格式”设置成:“程序数据库(/Zi)” 2.设置“链接器”------ ...
- 附加题找bug
private: void ReSize(int sz) { ) { return; } if(maxSize != sz) { T *arr = new T[sz]; if(arr == NULL) ...
- 【Golang 接口自动化01】使用标准库net/http发送Get请求
发送Get请求 使用Golang发送get请求很容易,我们还是使用http://httpbin.org作为服务端来进行演示. package main import ( "bytes&quo ...
- domContentload和onload
defer和async <script src="script.js"></script> 没有 defer 或 async,浏览器会立即加载并执行指定的脚 ...
- [Java学习] Java多态和动态绑定
在Java中,父类的变量可以引用父类的实例,也可以引用子类的实例. 请读者先看一段代码: 1. public class Demo { 2. public static void main(Strin ...
- 20170719xlVBASmartIndent
Public Sub SmartIndenterProcedure() Dim OneComp As VBComponent Dim StartLine As Long, EndLine As Lon ...
- ns-3
二.NS-3C++脚本的编写如前所述,NS-3的脚本使用C++语言(也支持python),使用四种类型的网络构件(Node.NetDevice.Channel.Application).一个简单的脚本 ...
- 原创-整理了下常用的js数组 、对象、数字、字符串的操作方法
终于整理好了...主要是一些常用的函数,包含es6和es5的所有常用的,吧一些不常用的全部砍掉,省的大家看的费事.发现这个到博客上面有点乱.给个百度云地址:https://pan.baidu.com/ ...