码迷,mamicode.com
首页 > 其他好文 > 详细

NBUT 1218 You are my brother

时间:2015-08-18 14:10:38      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:nbut

题目链接:https://ac.2333.moe/Problem/view.xhtml?id=1218

#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<climits>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#include<map>
using namespace std;
int main()
{
    int i,fa[2005];
    int n,a,b;
    while(~scanf("%d",&n))
    {
        for(i=0; i<=2005; i++)
            fa[i]=i;//先让自己是自己的父亲
        while(n--)
        {
            scanf("%d%d",&a,&b);
            fa[a]=b;//b是a的父亲
        }
        int h1,h2;
        h1=h2=0;
        int A=1;
        while(fa[A]!=A)
        {
            A=fa[A];
            h1++;
        }
        int B=2;
        while(fa[B]!=B)
        {
            B=fa[B];
            h2++;
        }
        if(h1>h2)
            printf("You are my elder\n");
        else if(h1<h2)
            printf("You are my younger\n");
        else
            printf("You are my brother\n");
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

NBUT 1218 You are my brother

标签:nbut

原文地址:http://blog.csdn.net/qq_30076791/article/details/47750555

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!