Nbut 1218 you is my brother

Source: Internet
Author: User

Title Link: 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;//First let yourself be your father while (n--)            {scanf ("%d%d", &a,&b);        Fa[a]=b;//b is A's father} 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&GT;H2) printf ("You Are my elder\n");        else if (H1&LT;H2) printf ("You Are my younger\n");    else printf ("You Are my brother\n"); } return 0;} 


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Nbut 1218 you is my brother

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.