Rev | Line | |
---|
[129] | 1 | //Author Antonio-Gabriel Sturzu |
---|
| 2 | |
---|
| 3 | #include<stdio.h> |
---|
| 4 | #include<time.h> |
---|
| 5 | #define lim 100001 |
---|
| 6 | |
---|
| 7 | int main() |
---|
| 8 | { |
---|
| 9 | int m[1000][1000],n,i,j,k; |
---|
| 10 | clock_t start,stop; |
---|
| 11 | FILE *f=fopen("royfloyd.in","r"); |
---|
| 12 | |
---|
| 13 | fscanf(f,"%i",&n); |
---|
| 14 | for(i=0;i<n;i++) |
---|
| 15 | for(j=0;j<n;j++) |
---|
| 16 | { |
---|
| 17 | fscanf(f,"%i",&m[i][j]); |
---|
| 18 | if(i!=j && m[i][j]==0) |
---|
| 19 | m[i][j]=lim; |
---|
| 20 | } |
---|
| 21 | fclose(f); |
---|
| 22 | |
---|
| 23 | start=clock(); |
---|
| 24 | for(k=0;k<n;k++) |
---|
| 25 | for(i=0;i<n;i++) |
---|
| 26 | for(j=0;j<n;j++) |
---|
| 27 | if(m[i][k]+m[k][j]<m[i][j]) |
---|
| 28 | m[i][j]=m[i][k]+m[k][j]; |
---|
| 29 | stop=clock(); |
---|
| 30 | printf("Au trecut %f secunde\n",(double)(stop-start)/CLOCKS_PER_SEC); |
---|
| 31 | f=fopen("royfloyd.out","w"); |
---|
| 32 | for(i=0;i<n;i++) |
---|
| 33 | { |
---|
| 34 | for(j=0;j<n-1;j++) |
---|
| 35 | { |
---|
| 36 | if(m[i][j]==lim) |
---|
| 37 | m[i][j]=0; |
---|
| 38 | fprintf(f,"%i ",m[i][j]); |
---|
| 39 | } |
---|
| 40 | if(m[i][n-1]==lim) |
---|
| 41 | m[i][n-1]=0; |
---|
| 42 | fprintf(f,"%i\n",m[i][n-1]); |
---|
| 43 | } |
---|
| 44 | fclose(f); |
---|
| 45 | return 0; |
---|
| 46 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.