void srcfss(stack *st, value cur) { #ifdef TREEDOT st->id = count; printf("ID = %zu\n", st->id); if (st->id) fprintf(st->dot, "\t%zu -> %zu;\n", (st - 1)->id, st->id); printcs(st); #endif count++; if (cur < min) { min = cur; sol = *st; } #ifdef LIMIT if (!stop) { gettimeofday(&t2, NULL); if ((double)(t2.tv_usec - t1.tv_usec) / 1e6 + t2.tv_sec - t1.tv_sec > LIMIT) stop = true; } #ifndef COMPLETEFRONTIER else return; #endif #endif #ifdef BOUND const value b = bound(st); #ifdef LIMIT if (stop) { if (b < bou) bou = b; return; } else #endif if (b >= min - MINGAIN) return; #endif chunk tmp[C], rt[C]; memcpy(tmp, st->c, sizeof(chunk) * C); MASKAND(tmp, st->r, tmp, C); edge popc = MASKPOPCNT(tmp, C); for (edge i = 0, e = MASKFFS(tmp, C); !stop && i < popc; i++, e = MASKCLEARANDFFS(tmp, e, C)) { agent v1 = X(st->a, e); agent v2 = Y(st->a, e); // At least one of the two coalitions must be a car if (!(st->dr[v1] + st->dr[v2])) continue; memcpy(rt, st->r, sizeof(chunk) * C); CLEAR(st->r, st->g[v1 * N + v2]); CLEAR(tmp, st->g[v1 * N + v2]); // Must not exceed the number of seats and the maximum number of drivers if (X(st->s, v1) + X(st->s, v2) > K || st->dr[v1] + st->dr[v2] > MAXDRIVERS) continue; CLEAR(st->c, st->g[v1 * N + v2]); st[1] = st[0]; memcpy(st[1].r, rt, sizeof(chunk) * C); merge(st + 1, v1, v2); contract(st + 1, v1, v2); st[1].l[v1] = minpath(st[1].cs + Y(st[1].s, v1), X(st[1].s, v1), st[1].dr[v1], st->sp); srcfss(st + 1, cur + COST(v1, st[1].dr, st[1].l) - COST(v1, st->dr, st->l) - COST(v2, st->dr, st->l)); } }
int main() { int a,b,n,i; scanf("%d",&n); int arr[n]; for(i=0;i<n;i++) scanf("%d",&arr[i]); scanf("%d %d",&a,&b); int path=minpath(arr,a,b,n); if(path==0) printf("Numbers a & b are not present in the array\n"); else printf("\nthe min path between %d and %d is %d\n",a,b,path); return 0; }
int main() { int i,j,n; scanf("%d",&n); int** A=(int**)malloc(sizeof(int*)); int** L=(int**)malloc(sizeof(int*)); for (i=0;i<n;i++) L[i]=(int*)malloc(sizeof(int)); for (i=0;i<n;i++) A[i]=(int*)malloc(sizeof(int)); minpath(A,n); return 0; }