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

Why 0.015 with O(N^2) algorithm?
Posted by keivan 26 Dec 2010 13:17
This is my ac code:

#include<iostream>
#include<queue>
#include<cstdio>
using namespace std;
bool a[100][100];
queue <int> l,s;
int p,u[100],n,fr,o=0;
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        u[i]=0;
        for(int j=0;j<n;j++)
            a[i][j]=false;
    }
    for(int i=0;i<n;i++)
    {
        p=1;
        while(1==1)
        {
            scanf("%d",&p);
            if(p==0)
            break;
            a[i][p-1]=true;
            u[p-1]++;
        }
    }
    for(int i=0;i<n;i++)
    if(u[i]==0)
        s.push(i);
    while(!s.empty())
    {
        o++;
        fr=s.front();
        s.pop();
        for(int i=0;i<n;i++)
            if(a[fr][i])
            {
                u[i]--;
                if(u[i]==0)
                    s.push(i);
            }
        printf("%d",fr+1);
        if(o!=n)
            printf(" ");
    }
printf("\n");
    return 0;
}
Re: Why 0.015 with O(N^2) algorithm?
Posted by Sepehr 29 Aug 2011 01:03
Hey
Probably because N <= 100 :-D