|
|
back to boardPlease help me, Crash #19 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. Re: Please help me, Crash #19 Your arrays are too small |
|
|