Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

诡异的很

Posted by xjtudaniel at 2009-10-19 21:50:22 on Problem 1655
网上找了一个AC的程序,对下面这个测试数据
10
1 2
1 3
2 4
2 5
4 8
5 9
3 6
3 7
10 1
11 2

输出为 1 5

自己程序测了好多数据都没问题,这个应该是2 5吧,结果总是WA,哪位高人能帮忙看看啊

#include <stdio.h>
#include <stdlib.h>

char a[20010][20010];
int visit[20010];
int min = -1;
int n,minn;


void clear()
{
     int i,j;
     for(i=0;i<20010;i++)
     {
           visit[i] = -1;
     }
     //memset(a,0,sizeof(a));
     min = -1;
     minn = 0;
}

int dfs(int u)
{
    int i,sum=0;
    int tempmax=0;
    visit[u] = 1;
    for(i=1;i<=n;i++)
    {
         if(a[u][i] == 'Y' && visit[i] == -1)
         {
             int temp = dfs(i);
             a[u][i] = a[i][u] = 'N';
             sum = sum + temp;
             if(temp > tempmax)
               tempmax = temp;
         }
    }
    int maxnow = tempmax > (n-1-sum) ? tempmax : (n-1-sum);
    if(min == -1 || ( min > maxnow || ( min == maxnow && u < minn )))
    {
         min = maxnow;
         minn = u;
    }
    return sum+1;
}

int main(void)
{
    int cases;
    scanf("%d",&cases);
    int i;
    for(i=0;i<cases;i++)
    {
        clear();
        int lines;
        scanf("%d",&lines);
        int j,k;
        n=1;
        for(j=0;j<lines;j++)
        {
           int v,u;
           scanf("%d %d",&v,&u);
           int tmpn = v > u ? v : u;
           if(n<tmpn)
              n = tmpn;
           a[v][u] = a[u][v] = 'Y';
        }
        for(j=1;j<=n;j++)
          for(k=j+1;k<=n;k++)
             if( a[j][k] == 'Y' )
                break;
        dfs(1);
        printf("%d %d\n",minn,min);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator