Advertisement
juanjo12x

Topologia_Estrella

Mar 30th, 2014
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <sys/time.h>
  5.  
  6. #define SIZEMAX 100
  7.  
  8. int grafo[SIZEMAX+1][SIZEMAX+1];int it=0;
  9. int estrella(int n){
  10.     int u,v;int salida;
  11.     for (u=1;u<=n;u++){
  12.       for(v=1;v<=n;v++){
  13.        if (grafo[u][v]==1) {
  14.           salida==1;
  15.          
  16.        }else{
  17.            salida==0;
  18.        }
  19.       it++;      
  20.       }
  21.       if (salida==1) return 1;
  22.     }
  23.     return 0;
  24. }
  25. int main(int argc, char** argv) {
  26.     int n,u,v,x,y;
  27.     clock_t start = clock();  
  28.    
  29.    
  30.    
  31.     //struct timeval start,end;    
  32.     scanf("%d",&n);
  33.     while(1){
  34.         scanf("%d",&x);
  35.         scanf("%d",&y);
  36.         if(x<0 || y<0) break;
  37.         grafo[x][y]=1;
  38.         grafo[y][x]=1;
  39.        
  40.     }
  41.     //gettimeofday(&start,NULL);
  42.     int topol=estrella(n);
  43.     //gettimeofday(&end,NULL);
  44.     //printf("%ld\n",((end.tv_sec*100000 + end.tv_usec)-(start.tv_sec*1000000 + start.tv_usec)));
  45.      printf("Tiempo transcurrido: %f \n", ((double)clock() - start) / CLOCKS_PER_SEC);
  46.     /*
  47.     for (u=1;u<=n;u++){
  48.         for(v=1;v<=n;v++) printf("%4d",grafo[u][v]);
  49.         printf("\n");
  50.     }
  51.     */
  52.  
  53.    if (topol){
  54.         printf ("Es topologia estrella \n");
  55.         printf ("El numero de iteraciones fue %d \n",it);
  56.         printf("El numero de vertices del grafo es : %d",n);
  57.    }else{
  58.        printf("No es topologia estrella ");
  59.      
  60.    }
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement