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

Common Board

please help me (problem 1045)
Posted by Bogdan A. Stoica [fireatmyself] 1 Oct 2005 15:14
I can't figure out the mistake in my algorithm for problem 1045.
Please help me.
Here is my code (i get WA at test #8) :

#include <stdio.h>
#define NMAX 1500

int N, K, V[NMAX], F[NMAX], A[NMAX][30], T[NMAX], L = NMAX;

void bfs(int d, int vf)
{
        int i;

        V[vf] = d;

        for (i = 0; i < F[vf]; i++)
            if (V[A[vf][i]] == -1)
            {
                T[ A[vf][i] ] = vf;
                bfs(d+1, A[vf][i]);
            }
}

int main()
{
        int i, a, b, j, l;

        scanf("%d %d", &N, &K);
        for (i = 1; i <= N; i++) V[i] = -1;
        for (i = 1; i < N; i++)
        {
                scanf("%d %d", &a, &b);
                A[a][F[a]++] = b;
                A[b][F[b]++] = a;
        }
        bfs(0, K);
        for (i = 1; i <= N; i++)
            if (F[i] == 1 && V[i]%2 == 1)
            {
                l = i;
                while (T[l] != K) l = T[l];
                if (L > l) L = l;
            }
        if (L != NMAX) printf("First player wins flying to airport %d\n", L);
        else printf("First player loses\n");
        return 0;

}

Edited by author 02.10.2005 00:17