-
Notifications
You must be signed in to change notification settings - Fork 0
/
kk.c
49 lines (48 loc) · 1.21 KB
/
kk.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int no_of_nodes,weight,starting_node,i=0,j=0;
scanf("%d",&no_of_nodes);
int cost_matrix[no_of_nodes][no_of_nodes];
for(i=0;i<no_of_nodes;i++)
{
for(j=0;j<no_of_nodes;j++)
{
scanf("%d",&weight);
if(weight<0)
{
printf("Weight of the edge %d - %d can not be negative",i+1,j+1);
exit (0);
}
if(i==j)
{
if(weight!=0)
{
printf("Weight of the edge %d - %d must be 0",i+1,j+1);
exit(0);
}
}
else
{
cost_matrix[i][j]=weight;
}
if(i>j)
{
if(weight!=cost_matrix[j][i])
{
printf("Weight of the edge %d - %d must be same as edge %d - %d",i+1,j+1,j+1,i+1);
exit(0);
}
else
{
cost_matrix[i][j]=weight;
}
}
}
}
scanf("%d",&starting_node);
return 0;
}