int main() { //FILE *fp = fopen("kargerAdj.txt","r"); freopen("kargerAdj.txt","r",stdin); char str[1000]; int i = 0; int s = 0; int e = 0; count = 0; while(scanf("%s",str)!= EOF) { if(strcmp (str ,"-1") == 0) { i = 0; count ++; continue;; } if( i == 0) { s = atoi(str); i ++; } else { e = atoi(str); tgraph[s][e] = 1; tgraph[e][s] = 1; i ++; } } //srand(time(NULL)); //count = 40; minCutCount = 9999; for (i = 0; i <= 100 ; i ++) { //srand(time(NULL)); for(int k = 1 ; k <= 40 ; k ++) for(int m = 1 ; m <= 40 ; m ++) graph[k][m] = tgraph[k][m]; int te = min_cut(); if(minCutCount > te) minCutCount = te; printf("%d\n",te); Sleep(2000); } printf("%d : %d",count ,minCutCount); return 0; }
int main(){ int min = INT_MAX; no_edges = 0; int max_edges; int v=0; int V[] = {1,2,3}; edges e[7800],er[7800]; int avn = 200; std::ifstream gp_read("kargerMinCut.txt",std::ios::in); int first_elem; int num; char ch; int flag = 1; std::string line; while(std::getline(gp_read,line)){ std::istringstream iss(line); v++; iss>>num; while(iss >> num){ if(num>v){ e[no_edges].V1 = v; e[no_edges].V2 = num; no_edges++; } } } avn = v; max_edges = no_edges; //srand(clock()); srand(clock()+GetTickCount()); for(int i=0;i<5000;i++){ count = v; //read file no_edges = max_edges; for(int j=0;j<no_edges;j++){ er[j].V1 = e[j].V1; er[j].V2 = e[j].V2; } int cross = min_cut(er,avn); if(cross==0) int a=1; if(cross<min) min = cross; std::cout << cross << "\t"; /*for(int i=0;i<no_edges;i++){ std::cout<<e[i].V1<<" "<<e[i].V2<<"\n"; }*/ } std::cout <<"\n"<< min; _getch(); return 0; }
void read_problems_write_answers() { int n_probs, i, n_cp, main_cp, j, prob_min_cut, a_cp; if (scanf("%d", &n_probs) != 1) exit(EXIT_FAILURE); for (i = 0; i < n_probs; i++) { if (scanf("%d %d", &n_cp, &main_cp) != 2) exit(EXIT_FAILURE); for (j = 1, prob_min_cut = INT_MAX; j < n_cp; j++) { if (scanf("%d", &a_cp) != 1) exit(EXIT_FAILURE); prob_min_cut = min(prob_min_cut, min_cut(main_cp, a_cp)); clear_graph(); } printf("%d\n", prob_min_cut); } }