#include using namespace std; const int MAX=51; int A[MAX][MAX], oldA[MAX][MAX]; struct edge { int A,B; }; edge Edges[MAX]; int Best, BestTwo, BestThree; int BestPR[MAX]; int BestOneTown; int d[MAX], pr[MAX]; int n, m; void PrintOptimal(){ cout<<" best distance form 0 to 1: "<0 && d[1] < BestThree){ BestThree = d[1]; //copy pr[] to BestPR[] for(int i=0;i0 && d[1] == BestThree){ //see if fewer legs if(Legs(pr) < Legs(BestPR)){ BestThree = d[1]; for(int i=0;i0){ pos = pr[pos]; p1[k++] = pos; } k=1; p2[0] = 1; pos = 1; while(pos>0){ pos = BestPR[pos]; p2[k++] = pos; } //now see if pr is lex before BestPR (possible they are ==, in which case, no update) //find 0 in the paths and work backwards k=0; while(p1[k]>0) k++; while(p1[k]==p2[k] && p1[k]!=1) k--; if(p1[k]>n; while(n>0){ initGrid(n); GetEdges(n); //find best pth with >2 legs - state pays for 2 BestThree = 1000000; for(int e1=0;e1>n; } return 0; }