I 've declared array big enough to read lines from input file, still i am getting runtime error (after executing for around 00.00.039s), i am trying FLOYD-WARSHALL to solve this... would anyone care to tell me why else i may get RE ???
[to Yile, what was your fault in your code??? may be same here

]
[EDIT: code is now attached, please,feel free to run this code and check if it fails (it sure does

) ... HELP]
Code: Select all
/*
10009
All Roads Leas Where?
*/
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
void print_path(int i, int j);
long parent[26][26], d[26][26];
char str[1000000], *p;
int main()
{
int m, n, i, j, k, u, v, test;
long temp;
gets(str);
p = strtok(str, " ");
test = atoi(p);
gets(str);
while (test --)
{
gets(str);
p = strtok(str, " ");
m = atoi(p);
p = strtok(NULL, " ");
n = atoi(p);
for (i=0; i<26; i++)
{
for (j=0; j<26; j++)
{
if (i == j)
d[i][j] = 0;
else
d[i][j] = INT_MAX - 200;
}
}
for (i=0; i<m; i++)
{
gets(str);
p = strtok(str, " ");
u = (int)(p[0] - 'A');
p = strtok(NULL, " ");
v = (int)(p[0] - 'A');
d[u][v] = d[v][u] = 1;
}
for (i=0; i<26; i++)
d[i][i] = 0;
for (i=0; i<26; i++)
{
for (j=0; j<26; j++)
{
if ((i == j) || (d[i][j] == INT_MAX - 200))
{
parent[i][j] = -1;
}
else if ((i != j) && (d[i][j] < INT_MAX - 200))
{
parent[i][j] = i;
}
}
}
for (k=0; k<26; k++)
{
for (i=0; i<26; i++)
{
for (j=0; j<26; j++)
{
temp = (d[i][k] + d[k][j]);
if (temp < d[i][j])
{
d[i][j] = temp;
parent[i][j] = parent[k][j];
}
}
}
}
for (i=0; i<n; i++)
{
gets(str);
p = strtok(str, " ");
u = (int)(p[0] - 'A');
p = strtok(NULL, " ");
v = (int)(p[0] - 'A');
print_path(u, v);
printf("\n");
}
if (gets(str) == NULL)
break;
else
printf("\n");
}
return 0;
}
void print_path(int i, int j)
{
if (i == j)
printf("%c", 'A' + i);
else
{
print_path(i, parent[i][j]);
printf("%c", 'A' + j);
}
}