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 1077. Travelling Tours

Could anyone tell me what's wrong on my program??(+)
Posted by Miguel Angel 28 Feb 2002 11:02
Thanks:).

#include<iostream.h>

unsigned char n;
char a[200][200];
unsigned char p[200];
char used[200];

void print(unsigned char i, unsigned char meta, unsigned char step)
{
    if (i!=meta) print(p[i],meta, step+1);
             else cout<<(short)step<<" ";
    cout<<(short)(i+1)<<" ";
}

void visit(unsigned char i)
{
unsigned char j;
    if (used[i])
    {
        print(p[i],i,1);
        cout<<endl;
        return;
    }
    used[i]=1;
    for (j=0; j<n; j++)
        if (a[i][j])
        {
            a[i][j]=0;
            a[j][i]=0;
            p[j]=i;
                visit(j);
        }
}

void main()
{
int  i, j, rings, how;
long m;
    cin>>n>>m;
    for (i=0; i<n; i++)
        for (j=0; j<n; j++) a[i][j]=0;
    while (m>0)
    {
        cin>>i>>j;
        --i,--j;
        a[i][j]=1;
        a[j][i]=1;
        --m;
    }
    rings=0;
    for (i=0; i<n; i++)
    {
        how=0;
        for (j=i+1; j<n; j++)
            how+=(short)a[i][j];
        if (how>0) rings=rings+how-1;
    }
    cout<<rings<<endl;
    for (j=0; j<n; j++) used[j]=0;
    for (i=0; i<n; i++)
     if (!used[i])
     {
        for (j=0; j<n; j++) p[j]=-1;
        visit(i);
     }
}
Note, that may be 1 or MORE component of graph.
Posted by Nazarov Denis (nsc2001@rambler.ru) 28 Feb 2002 12:34
> Thanks:).
>
> #include<iostream.h>
>
> unsigned char n;
> char a[200][200];
> unsigned char p[200];
> char used[200];
>
> void print(unsigned char i, unsigned char meta, unsigned char step)
> {
>     if (i!=meta) print(p[i],meta, step+1);
>              else cout<<(short)step<<" ";
>     cout<<(short)(i+1)<<" ";
> }
>
> void visit(unsigned char i)
> {
> unsigned char j;
>     if (used[i])
>     {
>         print(p[i],i,1);
>         cout<<endl;
>         return;
>     }
>     used[i]=1;
>     for (j=0; j<n; j++)
>         if (a[i][j])
>         {
>             a[i][j]=0;
>             a[j][i]=0;
>             p[j]=i;
>                 visit(j);
>         }
> }
>
> void main()
> {
> int  i, j, rings, how;
> long m;
>     cin>>n>>m;
>     for (i=0; i<n; i++)
>         for (j=0; j<n; j++) a[i][j]=0;
>     while (m>0)
>     {
>         cin>>i>>j;
>         --i,--j;
>         a[i][j]=1;
>         a[j][i]=1;
>         --m;
>     }
>     rings=0;
>     for (i=0; i<n; i++)
>     {
>         how=0;
>         for (j=i+1; j<n; j++)
>             how+=(short)a[i][j];
>         if (how>0) rings=rings+how-1;
>     }
>     cout<<rings<<endl;
>     for (j=0; j<n; j++) used[j]=0;
>     for (i=0; i<n; i++)
>      if (!used[i])
>      {
>         for (j=0; j<n; j++) p[j]=-1;
>         visit(i);
>      }
> }