问题描述

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.

输入

There are multiple test cases.

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.

输出

For each test case, if Little B is Little A’s younger, print “You are my younger”. Otherwise, if Little B is Little A’s elder, print “You are my elder”. Otherwise, print “You are my brother”. The output for each test case occupied exactly one line.

样例输入

5

1 3

2 4

3 5

4 6

5 6

6

1 3

2 4

3 5

4 6

5 7

6 7

样例输出

You are my elder

You are my brother

提示



来源

辽宁省赛2010

  1. #include<map>
  2. #include<set>
  3. #include<queue>
  4. #include<stack>
  5. #include<vector>
  6. #include<math.h>
  7. #include<cstdio>
  8. #include<sstream>
  9. #include<numeric>//STL数值算法头文件
  10. #include<stdlib.h>
  11. #include <ctype.h>
  12. #include<string.h>
  13. #include<iostream>
  14. #include<algorithm>
  15. #include<functional>//模板类头文件
  16. using namespace std;
  17. typedef long long ll;
  18. const int maxn=11000;
  19. const int INF=0x3f3f3f3f;
  20. int a,b,n;
  21. int fa[maxn];
  22. int main()
  23. {
  24. while(cin>>n)
  25. {
  26. int x1,x2,cot1,cot2;
  27. for(int i=0; i<maxn; i++)
  28. fa[i]=i;
  29. while(n--)
  30. {
  31. scanf("%d %d",&a,&b);
  32. fa[a]=b;
  33. }
  34. x1=1;
  35. cot1=0;
  36. while(fa[x1]!=x1)
  37. {
  38. x1=fa[x1];
  39. cot1++;
  40. }
  41. x2=2;
  42. cot2=0;
  43. while(fa[x2]!=x2)
  44. {
  45. x2=fa[x2];
  46. cot2++;
  47. }
  48. if(cot1>cot2)
  49. printf("You are my elder\n");
  50. else if(cot1<cot2)
  51. printf("You are my younger\n");
  52. else
  53. printf("You are my brother\n");
  54. }
  55. return 0;
  56. }

You are my brother NBUT - 1218的更多相关文章

  1. 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. On ...

  2. NBUT 1218 You are my brother

    $dfs$. 记录一下每一个节点的深度就可以了. #include<cstdio> #include<cstring> #include<cmath> #inclu ...

  3. NBUT 1457 莫队算法 离散化

    Sona Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Submit Status Practice NBUT 145 ...

  4. fzoj1314 You are my brother

    题目描述 Little A gets to know a new friend, Little B, recently. One day, they realize that they are fam ...

  5. ACM: NBUT 1107 盒子游戏 - 简单博弈

     NBUT 1107  盒子游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:  Practice  Appoint ...

  6. ACM: NBUT 1105 多连块拼图 - 水题 - 模拟

    NBUT 1105  多连块拼图 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:  Practice  Appoint ...

  7. 远程监控显示brother数控机床数据

    最近几个月公司太忙了,到现在已经连续出差两个多月了. 这个项目这要做mes系统,涉及到产品在机床的加工过程监控,然后led看板显示产品进度. 这里的主角是日本的brother数控机床,服务器按照一定频 ...

  8. 图论 --- spfa + 链式向前星 (模板题) dlut 1218 : 奇奇与变形金刚

    1218: 奇奇与变形金刚 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 130  Solved: 37[Submit][Status][Web Boa ...

  9. 【CodeVS 1218】【NOIP 2012】疫情控制

    http://codevs.cn/problem/1218/ 比较显然的倍增,但是对于跨过根需要很多讨论,总体思路是贪心. 写了一上午,不想再说什么了 #include<cstdio> # ...

随机推荐

  1. 【点分治练习题·不虚就是要AK】点分治

    不虚就是要AK(czyak.c/.cpp/.pas)  2s 128M  by zhb czy很火.因为又有人说他虚了.为了证明他不虚,他决定要在这次比赛AK. 现在他正在和别人玩一个游戏:在一棵树上 ...

  2. 教你 Shiro 整合 SpringBoot,避开各种坑(山东数漫江湖)

    依赖包 <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-sprin ...

  3. js中三种定义变量 const, var, let 的区别

    js中三种定义变量的方式const, var, let的区别 1.const定义的变量不可以修改,而且必须初始化. 1 const b = 2;//正确 2 // const b;//错误,必须初始化 ...

  4. Java开源爬虫框架crawler4j

    花了两个小时把Java开源爬虫框架crawler4j文档翻译了一下,因为这几天一直在学习Java爬虫方面的知识,今天上课时突然感觉全英文可能会阻碍很多人学习的动力,刚好自己又正在接触这个爬虫框架,所以 ...

  5. 区块链~Merkle Tree(默克尔树)算法解析~转载

    转载~Merkle Tree(默克尔树)算法解析 /*最近在看Ethereum,其中一个重要的概念是Merkle Tree,以前从来没有听说过,所以查了些资料,学习了Merkle Tree的知识,因为 ...

  6. deepin安装metasploit

    [1]安装metasploit 1.curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/tem ...

  7. CreateProcess中的部分参数理解

    函数原型,这里写Unicode版本 WINBASEAPIBOOLWINAPICreateProcessW( _In_opt_ LPCWSTR lpApplicationName, //可执行文件名字 ...

  8. selenium===selenium自动化添加日志(转)

    本文转自 selenium自动化添加日志 于logging日志的介绍,主要有两大功能,一个是控制台的输出,一个是保存到本地文件 先封装logging模块,保存到common文件夹命名为logger.p ...

  9. docker数据管理--数据卷的备份

    /* 先在宿主机创建一个备份的文 件夹, 然后将其以另外一个名字的目录挂载到容器里, 此时不管容器里,或宿主机里做什么操作, 数据都会及时更新,并得到备份. */ [root@localhost ~] ...

  10. Mui自定义时间格式:

    Mui自定义时间格式: (function($) { $.init(); $(document).on('tap','.btn',function(){ var obj = getFormJson($ ...