ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1045. Funny Game

O,I need help,can you tell me why this wrong,thank you
Posted by sherry 31 Jul 2008 13:42
#include<stdio.h>
#include<stdlib.h>
#define MAX 1002
int join[MAX][MAX],cont[MAX],used[MAX],win[MAX];
int np,mark,fri;
int tree(int aa)
{
    int i,j,k,mar=0,min1=MAX,min2=MAX;
    used[aa]=1;
    if(cont[aa]==1&&aa!=fri)//!!cout为1可为终点,亦可为起点~!!
    {
       win[aa]=aa;
        return 0;
    }
    for(i=1;i<=np;i++)
    {
        if(join[aa][i]&&!used[i])
        {

            k=tree(i);
            if(!k&&min1>win[i])
            {
                mar=1;
                min1=win[i];
            }
            if(k&&min2>win[i])
                min2=win[i];
        }
    }
    if(mar)
    {
        win[aa]=min1;
            return 1;
    }
    else
    {
        win[aa]=min2;
        return 0;
    }
}

int main()
{
    int i,j,k,mar=0;
    scanf("%d%d",&np,&fri);
    for(i=1;i<np;i++)
    {
        scanf("%d%d",&j,&k);
        join[j][k]=1;
        join[k][j]=1;
        cont[j]++;
        cont[k]++;
    }
    k=tree(fri);
    if(k)printf("First player wins flying to airport %d\n",win[fri]);
    else printf("First player loses\n");
//    system("pause");
    return 0;
}




Re: O,I need help,can you tell me why this wrong,thank you
Posted by sherry 31 Jul 2008 14:05
I find where I made the mistake,
I just misunderstand the porblem...