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

WA....实在找不出错在哪里。。。好心的大牛请进来看看~

Posted by SherlockBourne at 2007-05-15 14:53:31 on Problem 2230
#include<iostream>

using namespace std;

int             n, m, l;
int             edge[50000], path[500000];
int             findx[10000], findy[10000];
struct          node
{
    int         x, y, p;
}               edgex[50000], edgey[50000];

bool            cmpx(node a, node b)
{
    if (a.x < b.x)
        return true;
    else
        return false;
}

bool            cmpy(node a, node b)
{
    if (a.y < b.y)
        return true;
    else
        return false;
}

void            make(int k)
{
    int         i;
    for (i = findx[k]; i < m; i ++)
    {
        if (edgex[i].x != k)
           break;
        while (edge[edgex[i].p] > 0)
        {
            edge[edgex[i].p] --;
            make(edgex[i].y);
        }
    }
    for (i = findy[k]; i < m; i ++)
    {
        if (edgey[i].y != k)
           break;
        while (edge[edgey[i].p] > 0)
        {
            edge[edgey[i].p] --;
            make(edgey[i].x);
        }
    }
    path[l] = k;
    l ++;
}

int             main()
{
    int         i, a, b;
    while (scanf("%d%d", &n, &m) != -1)
    {
        for (i = 0; i < m; i ++)
        {
            scanf("%d%d", &a, &b);
            edgex[i].x = a - 1;
            edgex[i].y = b - 1;
            edgex[i].p = i;
            edgey[i].x = a - 1;
            edgey[i].y = b - 1;
            edgey[i].p = i;
            edge[i] = 2;
        }
        sort(edgex, edgex + m, cmpx);
        sort(edgey, edgey + m, cmpy);
        memset(findx, 0, sizeof(findx));
        memset(findy, 0, sizeof(findy));
        for (i = 0; i < m; i ++)
            if ((i == 0) || (edgex[i].x != edgex[i - 1].x))
                findx[edgex[i].x] = i;
        for (i = 0; i < m; i ++)
            if ((i == 0) || (edgey[i].y != edgey[i - 1].y))
                findy[edgey[i].y] = i;
        l = 0;
        make(0);
        for (i = l - 1; i >= 0; i --)
            printf("%d\n", path[i] + 1);
    }
} 


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