#include<stdio.h>
#include<conio.h>
#define MAX 10
int n,i,m[MAX][MAX],a[MAX][MAX],b[MAX][MAX],c[MAX][MAX];
int rt,count,k,j,l,d[MAX];
main()
{
clrscr();
int x;
printf("enter numberof nodes \n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("enter the connectivity of %d",i);
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
}
printf("enter the root node \n");
scanf("%d",&rt);
printf("\n the adjacent node of root node %d is",rt);
count=0;
for(j=1;j<=n;j++)
{
if((a[rt][j]==1)||(a[j][rt]==1))
{
printf("%d \t",j);
d[count]=j;
count=count+1;
}
}
d[count]=0;
for(i=0;i<count;i++)
{
k=d[i];
printf("enter the delay matrix of %d",k);
for(j=1;j<=n;j++)
scanf("%d",&b[k][j]);
printf("enter the delay from %d source to its adjacent node %d",rt,k);
scanf("%d",&c[rt][k]);
}
i=0;
k=d[i];
l=d[i+1];
for(j=1;j<=n;j++)
{
if((b[k][j]+c[rt][k])<=(b[l][j]+c[rt][l]))
m[rt][j]=b[k][j]+c[rt][k];
else
m[rt][j]=b[l][j]+c[rt][l];
}
k=2;
while(d[k]!=0)
{
x=d[k];
for(l=1;l<=n;l++)
{
if(m[rt][l]>=c[rt][x]+b[x][l])
{
m[rt][l]=c[rt][x]+b[x][l];
k=k+1;
}
}
}
printf("the delay vector of root node is \n");
for(j=1;j<=n;j++)
{
if(rt==j)
printf("0");
else
printf("%d",m[rt][j]);
}
}
No comments:
Post a Comment