/* Check behavior of the thr_row() code */ int testROW(int n) { int i, j, k = 0; int *a = randomM(n); int *b = (int *)malloc(n*n*sizeof(int)); counter = 0; memcpy(b, a, n*n*sizeof(int)); while (k < n) { pthread_mutex_lock(&c_lock); i = counter; counter++; pthread_mutex_unlock(&c_lock); if (i < n) { if (i != k) { for (j = 0; j < n; j++) { if (j != k) { if ((a[i*n+k] + a[k*n+j]) < a[i*n+j]) a[i*n + j] = a[i*n+k] + a[k*n+j]; } } } } else { counter = 0; k++; } } floyd(b, n); return compareM(a, b, n); }
int main() { int i, j, low, high, mid, value; scanf("%d%d%d", &machine_number, &cows_number, &process_number); for (i = 1; i <= machine_number + cows_number; i++) { for (j = 1; j <= machine_number + cows_number; j++) { scanf("%d", &original_map[i][j]); if (original_map[i][j] == 0) { original_map[i][j] = INF; } } } max_distance = min_distance = 0; floyd(); low = min_distance; high = max_distance; while (low <= high) { mid = (low + high) / 2; buildGraph(mid); value = edmondsKarp(); if (value == cows_number) { high = mid - 1; } else { low = mid + 1; } } printf("%d\n", low); return 0; }
int main(){ int n; while(scanf("%d",&n)==1&&n!=0){ bool table[101][101]={false}; int i,j,k; while(scanf("%d",&i)==1&&i!=0) while(scanf("%d",&j)==1&&j!=0) table[i][j]=true; floyd(table,n); int t,count; scanf("%d",&t); for(i=1;i<=t;i++){ count=0; scanf("%d",&j); for(k=1;k<=n;k++) if(!table[j][k]) count++; printf("%d",count); for(k=1;k<=n;k++) if(!table[j][k]) printf(" %d",k); putchar('\n'); } } return 0; }
int main() { init(); floyd(); printf("%d\n", bs()); return 0; }
void ejecutarFloyd(GtkWidget *object, gpointer user_data){ convertirEntry(); int **p = (int **)malloc(tamanio * sizeof(int *)); int i,j; for (i=0; i<tamanio; i++){ p[i] = (int *)malloc(tamanio* sizeof(int)); } int **matriz = (int **)malloc(tamanio * sizeof(int *)); for (i=0; i<tamanio; i++){ matriz[i] = (int *)malloc(tamanio * sizeof(int)); } for (i = 0; i < tamanio; ++i) { for (j = 0; j < tamanio; ++j) { matriz[i][j]=distanciasFloyd[i][j]; } } floyd(distanciasFloyd,tamanio,p); floydBeamer(matriz,distanciasFloyd,p,tamanio); //system("evince --fullscreen floyd.pdf"); }
int main(int argc,char *argv[]) { if(argc!=2){ //checks for valid arguments printf("\nInvalid arguments!!!!\n"); exit(0); } int length,i,j; int **distancearray,**patharray; length=parsefile(argv[1]); distancearray=allocatearray(length); patharray=allocatearray(length); populatearray(distancearray,length,argv[1]); initializepatharray(patharray,length); floyd(distancearray,patharray,length); printf("\nShortest paths are\n"); for(i=0;i<length;i++){ //prints shortest paths for(j=0;j<length;j++){ if(distancearray[i][j]<500 && i!=j){ printf("V%d",i+1); path(patharray,i,j); printf("V%d",j+1); printf("\n"); } } printf("\n"); } }
int main(int argc, char const** argv) { scanf("%d %d", &N, &K); for (auto i = 1; i <= K; ++i) { int n1, n2; scanf("%d %d", &n1, &n2); adj[n1][n2] = -1; adj[n2][n1] = 1; } floyd(); scanf("%d", &S); for (auto i = 1; i <= S; ++i) { int n1, n2; scanf("%d %d", &n1, &n2); printf("%d\n", adj[n1][n2]); } return 0; }
int main() { struct timeval s; double start,end,total; int a[20][20],n,r[20][20],i,j; printf("enter the number of nodes\n"); scanf("%d",&n); printf("enter the adjacency matrix\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } gettimeofday(&s,NULL); start=s.tv_sec+(s.tv_usec/1000000.0); floyd(a,r,n); printf("matrix is\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d\t",r[i][j]); } printf("\n"); } gettimeofday(&s,NULL); end=s.tv_sec+(s.tv_usec/1000000.0); total=end-start; printf("running time is %lf seconds\n",total); return 0; }
int main(){ int a,b; int runs; scanf("%d",&runs); while (runs--){ scanf("%d",&n); for (int i=0; i < n; ++i){ G[i][i] = 1; for (int j=i+1; j < n; ++j) G[i][j] = G[j][i] = 0; } for (int i=0; i < n; ++i){ scanf("%d %d %d %d",&S[i].A.x,&S[i].A.y,&S[i].B.x,&S[i].B.y); } for (int i=0; i < n; ++i){ for (int j=i+1; j < n; ++j){ if (DoLineSegmentsIntersect(S[i].A.x,S[i].A.y,S[i].B.x,S[i].B.y, S[j].A.x,S[j].A.y,S[j].B.x,S[j].B.y )) G[i][j] = G[j][i] = 1; } } floyd(); while (scanf("%d %d",&a,&b) && (a && b)){ if (G[a-1][b-1]) puts("CONNECTED"); else puts("NOT CONNECTED"); } if (runs) putchar('\n'); } return 0; }
int main() { init(); floyd(); solve(); return 0; }
/* Test of floyd() * Compares results of matrix after running floyd * to the expected value */ int testFLOYD(char *f1, char *f2) { int n, read; // test matrices FILE *in = fopen(f1, "r"); FILE *out = fopen(f2, "r"); // get n value read = fscanf(in, "%d\n", &n); if (!read) printf("Error: no values read\n"); // allocate space for the matrices int *a = (int *)malloc(sizeof(int)*n*n); int *b = (int *)malloc(sizeof(int)*n*n); // Read values into adjacency matrix readm(a, n, in); readm(b, n, out); // Run algorithm floyd(a, n); return compareM(a, b, n); }
int main(void) { int n, m, i, j, a, b; scanf("%d %d\n", &n, &m); for (i = 1; i <= n; i ++) for (j = 1; j <= n; j ++) map[i][j] = INT_MAX / 2; for (i = 0; i < m; i ++) { scanf("%d %d\n", &a, &b); map[a][b] = 1; } floyd(n); int ans = 0, temp; for (i = 1; i <= n; i ++) { temp = 0; for (j = 1; j <= n; j ++) if ((i != j) && (map[i][j] == 1 || map[j][i] == 1)) temp ++; if (temp == n-1) ans ++; } printf("%d", ans); return 0; }
int main() { int m, i, j, k, w; printf("enter n and m\n"); scanf("%d %d",&n,&m); printf("Enter m edges in <v1> <v2> <weight> format\n"); for(k=0;k<m;k++) { scanf("%d %d %d",&i,&j,&w); graph[i-1][j-1]=graph[j-1][i-1]=w; } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(graph[i][j]==0) graph[i][j]=graph[j][i]=1000000000; if(i==j) graph[i][j]=0; } } floyd(); for(i=0;i<n;i++) { for(j=0;j<n;j++) printf("%d\t",graph[i][j]); printf("\n"); } }
void proc() { scanf("%d %d", &n, &m); for(int i = 0; i < m; ++i) { int a, b; scanf("%d %d", &a, &b); adj[a][b] = 1; adj[b][a] = -1; } floyd(); int ans = 0; for(int i = 1; i <= n; ++i) { bool flag = true; for(int j = 1; j <= n; ++j) if(i != j && adj[i][j] == 0) flag = false; if(flag) ++ans; } printf("%d\n", ans); }
int main() { char str[32]; int i, j, k; while(1) { scanf("%d", &n); if(n == 0) break; for(i = 1;i <= n; i++) for(j = 1;j <= n; j++) adj[i][j] = (i == j ? ~0 : 0); while(1) { scanf("%d %d", &i, &j); if(i == 0 && j == 0) break; scanf("%s", str); k = encode(str); adj[i][j] = k; } floyd(); while(1) { scanf("%d %d", &i, &j); if(i == 0 && j == 0) break; decode(adj[i][j], str); printf("%s\n", str); } printf("\n"); } return 0; }
int g_main(int argc, char ** argv) { graph_t * g = adj_list_read<vex_t, weight_t>(cin, DINET); cout << g << endl; floyd(g); graph_destroy(g); return 0; }
int main(int argc, char * argv[]){ int n = 5, i; int **edge = generateMatrix(n); printMatrix(edge, n); int **result = floyd(n, edge); }
int main(int argc, char const *argv[]) { while (scanf("%d", &n), n) { input(); floyd(); output(); } return 0; }
int main() { setUp(); in(); floyd(); solve(); return 0; }
int main(int argc, char *argv[]) { while(input()) { floyd(); solve(); } return 0; }
/* Checks for correctness, comparing results of * serial and parallel implementations */ int testFLOYD(int n, int num) { int *a = randomM(n); int *b = (int *)malloc(n*n*sizeof(int)); memcpy(b, a, n*n*sizeof(int)); floyd(a, n); f_p(b, n, num); return compareM(a, b, n); }
void MainWindow::Buttons() { connect(m_pb_ok, SIGNAL(clicked()), this, SLOT(slot_pb_ok())); connect(m_le_countTops, SIGNAL(textEdited(QString)), this,SLOT(slot_set_table(QString))); connect(m_le_density,SIGNAL(textEdited(QString)), this, SLOT(slot_densityChanged())); connect(this, SIGNAL(setMatrix(int,int,int)),m_math, SLOT(set_matrix(int,int,int))); connect(this, SIGNAL(calcFloid()), m_math, SLOT(floyd())); connect(this, SIGNAL(getResults(int,int)), m_math, SLOT(get_results(int,int))); connect(this, SIGNAL(clearMatrix()), m_math, SLOT(clear_Matrix())); }
int main() { int k,i,u,v,len,cas=0; while(scanf("%d%d%d",&n,&m,&q),n+m+q) { cas++; if(1 != cas) { printf("\n"); } printf("Case %d:\n",cas); chu(); for(i=0;i<m;i++) { scanf("%d%d%d",&u,&v,&len); add(u+1,v+1,len); } for(i=0;i<q;i++) { scanf("%d\n",&k); if(0 == k) { scanf("%d",&u); u++; if(1 == mark[u]) { printf("ERROR! At point %d\n",u-1); continue; } mark[u]=1; floyd(u); } else { scanf("%d%d",&u,&v); u++; v++; if(0 == mark[u] || 0 == mark[v]) { printf("ERROR! At path %d to %d\n",u-1,v-1); continue; } if(INF == map[u][v]) { printf("No such path\n"); } else { printf("%d\n",map[u][v]); } } } } return 0; }
int main(int argc, char const *argv[]) { int casen; scanf("%d", &casen); for (int ci=1; ci<=casen; ci++) { input(); floyd(); output(ci); } return 0; }
float Query::matchQuality(HashGraph* Gdb, GraphMatch* gm) { int** Dq=new int*[G->n()]; for(int i=0; i<G->n(); i++) Dq[i]=new int[G->n()]; floyd(G, Dq); int** Ddb=new int*[Gdb->n()]; for(int i=0; i<Gdb->n(); i++) Ddb[i]=new int[Gdb->n()]; floyd(Gdb, Ddb); float distance=0; int count=0; NodeMappingSet::iterator iter1, iter2; for(iter1=gm->mappings.begin(); iter1!=gm->mappings.end(); iter1++) { iter2=iter1; iter2++; for(; iter2!=gm->mappings.end(); iter2++) { if(Dq[iter1->source][iter2->source]!=INFIN && Ddb[iter1->target][iter2->target]!=INFIN) { distance+=abs(Dq[iter1->source][iter2->source]-Ddb[iter1->target][iter2->target]); count++; } } } for(int i=0; i<Gdb->n(); i++) delete [] Ddb[i]; delete [] Ddb; for(int i=0; i<G->n(); i++) delete [] Dq[i]; delete [] Dq; return distance+(G->n()-gm->mappings.size())*3; }
int main(int argc, char *argv[]) { while(1){ scanf("%d", &n_vetex); if (n_vetex == 0) break; init(); floyd(); query(); printf(" \n"); } return 0; }
int main(void){ int i,j; int vcount; while(1){ scanf("%d",&N); if(N==0){ break; } memset(d,-1,sizeof(d)); for(i=1;i<=N;i++){ scanf("%d",&vcount); while(vcount--){ scanf("%d",&j); scanf("%d",&d[i][j]); } } floyd(); int min_source=1; int result=-1; int row_max; for(i=1;i<=N;i++){ row_max=-1; for(j=1;j<=N;j++){ if(i==j){ continue; } if(d[i][j]==-1){//存在该点到达不了的点,因此不能选它做起点 row_max=-1; break; } if(d[i][j]>row_max){ row_max=d[i][j]; } } if(row_max!=-1&&(result==-1||row_max<result)){ min_source=i; result=row_max; } } if(result==-1){//没有一个点可以到其他各点,图不连通 printf("disjoint\n"); }else{ printf("%d %d\n",min_source,result); } } return 0; }
int main(void) { double min=0.0, lower=0.0; freopen("cowtour.in", "r", stdin); freopen("cowtour.out", "w", stdout); scanf("%d", &lim); for(int i=0; i<lim; i++) scanf("%d%d\n", &pos[i].x, &pos[i].y); for(int i=0; i<lim; i++){ char c; for(int j=0; j<lim; j++){ scanf("%c", &c); if(c == '1'){ int tx=pos[i].x-pos[j].x; int ty=pos[i].y-pos[j].y; dis[i][j] = dis[j][i] = sqrt(tx*tx+ty*ty); }else dis[i][j] = dis[j][i] = 0.0; } scanf("%c", &c); } floyd(); for(int i=0; i<lim; i++){ max[i] = dis[i][0]; for(int j=1; j<lim; j++){ if(i!=j && great(dis[i][j], max[i])) max[i] = dis[i][j]; } if(equal(lower, 0.0) || great(max[i], lower)) lower = max[i]; } for(int i=0; i<lim; i++){ for(int j=i+1; j<lim; j++){ if(equal(dis[i][j], 0.0)){ int tx=pos[i].x-pos[j].x; int ty=pos[i].y-pos[j].y; double d=sqrt(tx*tx+ty*ty)+max[i]+max[j]; if(equal(min, 0.0) || little(d, min)) min = d; } } } if(little(min, lower)) min = lower; printf("%.6lf\n", min); return 0; }
int main (int argc, char** argv) { int n = 200; double p = .05; const char* ifname = NULL; const char* ofname = NULL; //args extern char* optarg; const char* optstring = "hn:d:p:o:i:"; int c; while ((c = getopt(argc, argv, optstring)) != -1) { switch (c) { case 'h': fprintf(stderr, "%s", usage); return -1; case 'n': n = atoi(optarg); break; case 'p': p = atof(optarg); break; case 'o': ofname = optarg; break; case 'i': ifname = optarg; break; } } //make graph + output int* l = gen_graph(n,p); if(ifname) write_matrix(ifname, n, l); double start = omp_get_wtime(); infinitize(n,l); floyd(l,n); deinfinitize(n,l); double end = omp_get_wtime(); printf("== OpenMP with %d threads\n", omp_get_max_threads()); printf("n: %d\n", n); printf("p: %g\n", p); printf("Time: %g sec\n", (end-start)); printf("Check: %X\n", fletcher16(l, n*n)); //output if(ofname) write_matrix(ofname,n,l); free(l); return 0; }
int main() { int i, j, wt, k, n, top; int stack[MAX]; n = 7; for(i = 0; i < n; i++) { stack[i] = -1; } initCost(); floyd(n); for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { wt = weight[i][j]; if( i != j && wt != MAXCOST) { printf("DIST(V%d,V%d)=%d\n", i+1, j+1, wt); //采用栈来输出最短路径所经过的顶点 k = j; if(path[i][k] != 0) { top = -1; while(path[i][k] != 0) { stack[++top] = path[i][k]; k = path[i][k]; } printf("V%d --> ", i+1); while(top != -1) { printf("V%d", stack[top--]+1); if(top != -1) printf(" --> "); } printf(" --> V%d\n", j+1); } else { printf("V%d --> V%d\n", i+1, j+1); } } } } return 0; }