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 1022. Genealogical Tree

What's wrong? I got CE!
Posted by Borech 24 Jul 2003 22:14
#include <iostream.h>

const int max=100;
int N, G[max][max], color[max], sorted[max], last_sorted;

///////////////////////////////////////

void DFS_VISIT(int i)
{
    color[i]=1;

    for(int j=1;G[i][j]!=0;j++) {
        if (color[G[i][j]]==0)
            DFS_VISIT(G[i][j]);
    }

    color[i]=2;
    last_sorted++;
    sorted[last_sorted]=i;
}

void DFS()
{
    for(int i=1;i<=N;i++) {
        color[i]=0;
    }
    for(i=1;i<=N;i++)
        if (color[i]==0)
            DFS_VISIT(i);
}

//////////////////////////////////////

int main() {
    cin >> N;

    for(int i=1;i<=N;i++) {
        int x=1;
        for(int j=1;x!=0;j++) {
            cin >> x;
            G[i][j]=x;
        }
    }

    last_sorted=0;
    DFS();

    for(i=last_sorted;i>0;i--)
        cout << sorted[i] << ' ';
    return 0;
}
Don't use "max" identifier - it's standard function of 32-bit C/C++ compilers (-)
Posted by Mad Mouse 25 Jul 2003 03:05