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 1434. Buses in Vasyuki

Dijkztra Please help me, Crash #19 [1] // Problem 1434. Buses in Vasyuki 22 Aug 2011 12:18
Can someone help me to debug this C++ code? It got crash at 19th test-case.

#include<cstdio>
#include<vector>
#include<queue>
using namespace std;

vector<int> p[1005];
vector<int> idxs[10005];
int dist[10005];
int bef[10005];
queue<int> q;

void print(int n)
{
    if(n!=-1)
    {
        print(bef[n]);
        printf("%d ",n);
    }
}

int main()
{
    int n,m,c,d,awl,akh,tmp;
    bool sudah = false;
    scanf("%d%d",&m,&n);
    for(c=0;c<=n;c++)
    {
        dist[c] = 10000000;
        bef[c] = -1;
    }
    for(c=0;c<m;c++)
    {
        scanf("%d",&d);
        while(d--)
        {
            scanf("%d",&tmp);
            p[c].push_back(tmp);
            idxs[tmp].push_back(c);
        }
    }
    scanf("%d%d",&awl,&akh);
    dist[awl] = 0;
    q.push(awl);
    while(!q.empty())
    {
        tmp = q.front();
        q.pop();
        n = idxs[tmp].size();
        for(c=0;c<n;c++)
        {
            m = p[idxs[tmp][c]].size();
            for(d=0;d<m;d++) if(p[idxs[tmp][c]][d]!=tmp) if(dist[p[idxs[tmp][c]][d]] > dist[tmp]+1)
            {
                dist[p[idxs[tmp][c]][d]] = dist[tmp] + 1;
                bef[p[idxs[tmp][c]][d]] = tmp;
                if(p[idxs[tmp][c]][d]==akh) sudah = true;
                else q.push(p[idxs[tmp][c]][d]);
            }
            if(sudah) break;
        }
        if(sudah) break;
    }
    if(dist[akh]==10000000)
    {
        printf("-1\n");
        return 0;
    }
    printf("%d\n",dist[akh]);
    print(akh);
    printf("\n");
    return 0;
}

Thanks in advance.
Alexey Dergunov [Samara SAU] Re: Please help me, Crash #19 // Problem 1434. Buses in Vasyuki 27 Jun 2012 01:06
Your arrays are too small