kamacoder-solutions icon indicating copy to clipboard operation
kamacoder-solutions copied to clipboard

共同祖先问题

Open jackwentao opened this issue 1 year ago • 0 comments

#include

using namespace std; int main(){ int n; while(cin>>n){

    int index;
    int value;
    int ming = 1;
    int yu = 2;
    int a = 1;
    for(int i = 0; i < n; i++){
        cin>>index>>value;
        if(ming == index){
            ming = value;
        }
        if(yu == index){
            yu = value;
        }
        if((ming == n+1 || yu == n+1) && a){
            a = 0;
            if(ming == yu){
                cout<<"You are my brother"<<endl;
            }else if( ming == n+1){
                cout<<"You are my younger"<<endl;
            }else{
                cout<<"You are my elder"<<endl;
            }
        }

    }
    
}
return 0;

}

jackwentao avatar Nov 03 '23 09:11 jackwentao