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 1176. Hyperchannels

What is incorrect in this program???Please give me a test on which it fails
Posted by King Without Kingdom 22 Jul 2002 02:46
#include<iostream.h>
int*conn[1001];
int*done[1001];
int quan[1001];
void razrul(int);
int *tstr;
void main(){
    int str[1001];
    tstr=new int[32200];
    int i,j,n,q,a;
    cin >> n >> a;
    a--;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
            cin >> str[j];
        q=0;
        str[i]=1;
        for(j=0;j<n;j++)
            if(str[j]==0)
                q++;
        if(q!=0)
        {
            conn[i]=new int[q];
            done[i]=new int[q];
        }
        quan[i]=0;
        for(j=0;j<n;j++)
            if(str[j]==0)
            {
                conn[i][quan[i]]=j;
                done[i][quan[i]]=0;
                quan[i]++;
            }
    }
    razrul(a);
}
void razrul(int a){
    tstr[0]=a;
    int *tstr1;
    int ptstr=1,a0=a,i;
    while(1)
    {
        for(i=0;i<quan[a];i++)
            if(done[a][i]==0)
            {
                done[a][i]=1;
                a=conn[a][i];
                tstr[ptstr]=a;
                ptstr++;
                break;
            }
        if(a==a0)
            break;
    }
    if(ptstr!=1)
        tstr1=new int[ptstr];
    else
        return ;
    for(i=0;i<ptstr;i++)
        tstr1[i]=tstr[i];
    for(i=0;i<ptstr-1;i++)
    {
        cout <<tstr1[i]+1<<" "<<tstr1[i+1]+1<<"\n";
        razrul(tstr1[i+1]);
    }
}