Your is my brother time limit:MS | Memory limit:65535 KB Difficulty:3
-
Describe
-
Little a gets to know a new friend, Little B, recently. One day, they realize that they is family years ago. Now, Little A wants to know whether Little B are his elder, younger or brother.
-
-
Input
-
-
There is multiple test cases.
The first line have a single integer, N (n<=1000). The next n lines has 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
-
-
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 is occupied exactly one line.
-
-
Sample input
-
-
51 32 43 54 65 661 32 43 54 65 76 7
-
-
Sample output
-
-
You are my elderyou is my brother
#include <stdio.h> #include <string.h> #define MAX 2100#define max (x, y) (x>y?x:y) int set[max];int sum, sum1,sum2;void dfs (int beg,int end) {if (Set[beg]==beg) return; int i;for (i=1;i<=sum;i++) {if (set[beg]==i)//Determines whether it is a parent node {if (end==1)//If the parent node of 1 is added 1 sum1++;else //is 2 of the parent node sum2++;d FS (i,end);//continue searching for break;}}} void Chu () {int i;for (i=0;i<max;i++) set[i]=i;} void Shu () {if (sum1==sum2) printf ("You Are My brother\n"), else if (sum1>sum2) printf ("You Are my elder\n"); elseprintf (" You are my younger\n ");} int main () {int n,m,j,i,k,t,s;while (scanf ("%d", &t)!=eof) {chu (); Sum=0;while (t--) {scanf ("%d%d", &n,&m); Set[n]=m;sum=max (Max (n,m), sum);} Sum1=sum2=0;dfs (;D) FS (2,2); Shu ();} return 0;}
Nyoj 282 You is my brother