Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int MinForInf (int , int ) ;
- int p (int,int,int,int**) ;
- void solve (int , int ** ) ;
- int MinForInf(int a , int b ){
- if (a==-1) return b ;
- if (b==-1) return a ;
- if (a>b) return b;
- else return a;
- }
- int p ( int i , int j , int k , int **array){
- if (k>=0)
- return MinForInf( p(i,j,k-1,array), ( p(i,k,k-1,array)+p(k,j,k-1,array)) );
- else
- return array[i][j];
- }
- void solve (int n , int **array){
- int i,j,k;
- int cost;
- for (i=0 ; i<=n ; i++){
- for (j=0 ; j<i ; j++){
- cost=p(i,j,n,array);
- printf ("form node %d to node %d cost is %d \n " , i,j, cost);
- }
- printf("\n");
- }
- for (i=0 ; i<n ; i++) {
- printf("\n");
- for (j=0 ;j<=i ; j++)
- printf("%d \t " , array[i][j]);
- }
- }
- int main (void) {
- int **graph;
- int i,j, n ;
- printf("Give num of cities\n");
- scanf("%d" ,&n );
- printf("%d" , n);
- n=n-1;
- graph=malloc(n*sizeof(int *));
- for (i=0 ; i<n ; i++)
- graph[i]=malloc(n* sizeof(int ));
- for (i=0 ; i<n ; i++){
- for (j=0 ; j<=i ; j++)
- scanf("%d" , &graph[i][j]);
- }
- for (i=0 ; i<n ; i++) {
- printf("\n");
- for (j=0 ;j<=i ; j++)
- printf("%d \t " , graph[i][j]);
- }
- solve (n,graph);
- for (i=0 ; i<n ; i++) {
- printf("\n");
- for (j=0 ;j<=i ; j++)
- printf("%d \t " , graph[i][j]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement