示例#1
0
int main()
{
    int i,u,v,w;
    freopen("poj3613.txt","r",stdin);
    freopen("poj3613ans.txt","w",stdout);
    while (scanf("%d%d%d%d",&n,&t,&s,&e)!=EOF)
    {
        memset(id,-1,sizeof(id));
        memset(map,inf,sizeof(map));
        memset(ans,inf,sizeof(ans));
        for (i=0;i<MaxN;i++) ans[i][i]=0;
        pointnum=0;
        for (i=1;i<=t;i++)
        {
       	    scanf("%d%d%d",&w,&u,&v);
       	    AddEdge(u,v,w);
        }
        while (n)
        {
       	    if (n&1) Floyd(ans,map,ans);
       	    n>>=1;
       	    Floyd(map,map,map);
        }
        printf("%d\n",ans[id[s]][id[e]]);
    }
} 
示例#2
0
文件: aciclico.c 项目: YiseKai/UCA
int aciclico (Grafo G)
{
    /*Hemos modificado Floyd para que no inicialice la diagonal a 0, ya que será esta la que
    utilizaremos para comprobar si el grafo proporcionado es acíclico.
    Si es INFINITO significa que no hay ciclos, por lo que el grafo será acíclico (devuelve 1)
    */
    
    tCoste costesminimos[N][N];
    vertice caminos[N][N];
    int i;
    
    //utilizamos el algoritmo de Floyd
    Floyd(G, costesminimos, caminos);
    
    //Imprimimos las matrices que hemos obtenido con el algoritmo de Floyd
    ImprimirMCostes(costesminimos, G);
    ImprimirMCaminos(caminos, G);
    
    for(i=0; i<G->numVert; i++)
        if(costesminimos[i][i] != -1)
            return 0; //no es acíclico (tiene ciclos)
    
    return 1; //si toda la diagonal es INFINITO (-1), significa que es acíclico, luego no tiene ciclos
    
       
}
示例#3
0
int main(int argc, char* argv[]) {
   int  n;
   int* local_mat;
   MPI_Comm comm;
   int p, my_rank;

   MPI_Init(&argc, &argv);
   comm = MPI_COMM_WORLD;
   MPI_Comm_size(comm, &p);
   MPI_Comm_rank(comm, &my_rank);

   if (my_rank == 0) {
      printf("How many vertices?\n");
      scanf("%d", &n);
   }
   MPI_Bcast(&n, 1, MPI_INT, 0, comm);
   local_mat = malloc(n*n/p*sizeof(int));

   if (my_rank == 0) printf("Enter the local_matrix\n");
   Read_matrix(local_mat, n, my_rank, p, comm);
   if (my_rank == 0) printf("We got\n");
   Print_matrix(local_mat, n, my_rank, p, comm);
   if (my_rank == 0) printf("\n");

   Floyd(local_mat, n, my_rank, p, comm);

   if (my_rank == 0) printf("The solution is:\n");
   Print_matrix(local_mat, n, my_rank, p, comm);

   free(local_mat);
   MPI_Finalize();

   return 0;
}  /* main */
示例#4
0
文件: main.cpp 项目: linmx0130/OJCode
void Main()
{
	N=K+C;
	int L=1,R=0;
	for (int i=1;i<=N;++i)
	{
		for (int j=1;j<=N;++j)
		{
			scanf("%d",&Dis[i][j]);
			if (Dis[i][j]==0 && i!=j) Dis[i][j]=0x7000000;
		}
	}
	Floyd();
	for (int i=1;i<=K;++i)
	{
		for (int j=K+1;j<=N;++j) if (R<Dis[i][j]) R=Dis[i][j];
	}
	while (L<R)
	{
		int mid=(L+R)>>1;
		if (Check(mid))
		{
			R=mid;
		}
		else 
		{
			L=mid+1;
		}
	}
	printf("%d\n",L);
}
示例#5
0
文件: Floyd.cpp 项目: Lee-W/learning
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            scanf("%d", &dis[i][j]);
    Floyd(n);
}
示例#6
0
void CFloydDlg::OnStart() 
{
	int Price=0;
	CString Text;
	UpdateData();
	int Tops=Graph->GetTops();
 	if (m_Source<1 || m_Source>Tops || m_Destination <1 || m_Destination > Tops)
	{
		MessageBox("Wrong parameter!",CaptionText,MB_OK);
		return;
	}
	while (m_PathCtrl.GetCount()>0) m_PathCtrl.DeleteString(0);

	CQuery* PathQuery=new CQuery;
	int* T = new int[Tops*Tops];
	int* H = new int[Tops*Tops];
	Floyd(Graph,PathQuery, T, H, m_Source,m_Destination,Price);

	while (!PathQuery->IsEmpty())
	{
		Text.Format("%d",PathQuery->Pop());
		m_PathCtrl.AddString(Text);
	}
	m_TCtrl.SetCols(Tops+1);
	m_TCtrl.SetRows(Tops+1);
	m_HCtrl.SetCols(Tops+1);
	m_HCtrl.SetRows(Tops+1);
	
	for (int i=1; i<=Tops; i++) 
	{
		Text.Format("%d",i);
		m_HCtrl.SetTextMatrix(0,i,Text);
		m_HCtrl.SetTextMatrix(i,0,Text);
		m_TCtrl.SetTextMatrix(0,i,Text);
		m_TCtrl.SetTextMatrix(i,0,Text);
		m_HCtrl.SetColWidth(i,320);
		m_TCtrl.SetColWidth(i,320);
	}
	m_HCtrl.SetColWidth(0,300);
	m_TCtrl.SetColWidth(0,300);
	for (i=1; i<=Tops; i++)
	{
		for (int j=1; j<=Tops; j++)
		{
			Text.Format("%d",H[(i-1)*Tops+j-1]);
			m_HCtrl.SetTextMatrix(i,j,Text);
			Text.Format("%d",T[(i-1)*Tops+j-1]);
			m_TCtrl.SetTextMatrix(i,j,Text);
		}
	}
	m_Price.Format("%d",Price);
	delete []H;
	delete []T;
	delete PathQuery;
	UpdateData(0);
}
示例#7
0
文件: uva10985.cpp 项目: ksBSB/ACM
int main () {
	int cas;
	scanf("%d", &cas);
	for (int i = 1; i <= cas; i++) {
		init();
		Floyd();
		printf("Case #%d: %d\n", i, solve() );
	}
	return 0;
}
void Solve()
{
    int ss, tt;
    while ( ~scanf("%d %d", &ss, &tt), ss+tt!=-2 )
    {
        Initalize( ss, tt );
        Floyd( ss );
        output( ss, tt );
    }// start point and destination
}// Solve
int main()
{
    freopen("E:\\cowtour.in", "r", stdin);
    freopen("E:\\cowtour.out", "w", stdout);

    ReadData();
    Floyd();
    Solve();
    
    return 0;
}
void main()
{
	int i, j, cp;
	MTGraph G;
	IniMGraph_directed(&G);
	VertexData v[]={'a', 'b', 'c', 'd', 'e','f'};//顶点集
	EdgeData e[NumVertices][NumVertices]={
		{0,3,MaxValue,4,MaxValue,5},
		{MaxValue,0,1, MaxValue, MaxValue,1},
		{MaxValue, MaxValue,0,2,MaxValue,MaxValue},
		{MaxValue,3,MaxValue,0,MaxValue,MaxValue},
		{MaxValue, MaxValue, MaxValue,3,0,2},
		{MaxValue,MaxValue,MaxValue,2,MaxValue,0}
	};//边集,邻接矩阵
	CreateMGraph_directed(&G, v, e, 6);

	EdgeData A[NumVertices][NumVertices]={0};
	int A1[NumVertices][NumVertices]={0};
	int P[NumVertices][NumVertices];
	
	Floyd(A, G, P, G.n);
	cout<<"每一对顶点之间的最短路径:"<<endl;
	for(i=0; i<G.n; i++)
	{
		for(int j=0; j<G.n; j++)
			cout<<A[i][j]<<'\t';
		cout<<endl;
	}
	cout<<"相通节点之间的路径长以及中间节点: "<<endl;
	for(i=0; i<G.n; i++)
		for(j=0; j<G.n; j++)
		{
			if(A[i][j]<MaxValue)
			{
				cout<<G.vexlist[i]<<"->"<<G.vexlist[j]<<", 最短路径长度: "<<A[i][j]<<", 中间结点"<<':'<<endl;;		
				Path(P, i, j);
			}
		}
//求传递闭包
	Warshall(A1, G, G.n);
	cout<<"\n传递闭包为:"<<endl;
	for(i=0; i<G.n; i++)
	{
		for(int j=0; j<G.n; j++)
			cout<<A1[i][j]<<'\t';
		cout<<endl;
	}
//求中心节点
	CenterPoint(A, G.n, cp);
	cout<<"\n\n中心点为: "<<G.vexlist[cp+1]<<endl;

}
示例#11
0
文件: butter.cpp 项目: jingcmu/USACO
int main(void)
{
	int i,shortPath=2147483647;
	input();
	Floyd();
	getShortest();
	for(i=1;i<=P;i++)
	{
		if(shortPath>shortest[i])
			shortPath=shortest[i];
	}
	fprintf(fout,"%d\n",shortPath);
	return 0;
}
示例#12
0
文件: 117.cpp 项目: jjDiego/EDA
void Cal(int sum) {
	int i, od1 = -1, od2 = -1;
	for(i = 0; i<30; i++)
		if(F[i] % 2) break;
	od1 = i;
	for(i = 29; i>=0; i--)
		if(F[i] % 2) break;
	od2 = i;
	if(od1 <0 && od2<0 ) {
		printf("%d\n",sum);
		return;
	}
	Floyd();
	printf("%d\n",sum+Link[od1][od2]);
		
}
示例#13
0
int main()
{
    int N, E, i, p, j;
    VertexType n1, n2;


    scanf("%d %d", &N, &E);
    MGraph G = CreateMGraph(N, E);
    while (E--)
    {
        scanf("%d %d %d", &n1, &n2, &p);
        SetEdge(G, n1 - 1, n2 - 1, p);
    }

    Floyd(G);
    int min = INFINITY, index = N;
    int flag = 0;
    for (int i = 0;i < G->numNodes; i++)
    {
        int t = 0;
        for (int j = 0; j < G->numNodes; j++)
        {
            if (i != j && D[i][j] == INFINITY)
            {
                flag = 1;
                break;
            }
            if (i != j && D[i][j] > t)
            {
                t = D[i][j];
            }
        }
        if (t < min)
        {
            min = t;
            index = i;
        }
    }
    if (flag)
        printf("0\n");
    else
        printf("%d %d",index + 1,min);

    return 0;
}
示例#14
0
main() {
	while(scanf("%d %d", &n, &m) == 2) {
		memset(Trea, 0, sizeof(Trea));
		int a, b, find = 0, x;
		for(a = 1; a <= m; a++)
			scanf("%d", &Trea[a]);
		for(a = 0; a < m; a++)
			next[a] = a+1;
		next[m] = 0;
		for(a = 1; a <= n; a++)
			for(b = 1; b <= n; b++)
				scanf("%d", &map[a][b]);
		Floyd();
		if(Trea[1] == 1)	find++, next[0] = next[1];
		Ans = oo, DFS(1, find, 0);
		printf("%d\n", Ans);
	}
	return 0;
}
main ()
{
        freopen ( "p.in" , "r" , stdin );
        freopen ( "p.out" , "w" , stdout );
        
        int     step = 0;
        int     totalask , a , b;
        while ( init ()) {
                step ++;
                Floyd ();
                printf ( "Test Set #%d\n" , step );
                scanf ( "%d" , &totalask );
                while ( totalask ) {
                        scanf ( "%d %d" , &a , &b );
                        printf ( "%d to %d: %d\n" , a , b , Long [a - 1] [b - 1] );
                        totalask --;
                }
                printf ( "\n" );
        }
}
示例#16
0
int main()
{
	int d,i,j,k,x,ans;
	while(scanf("%d %d",&n,&d)==2)
	{
		for(i=0;i<n;i++)for(j=0;j<n;j++)dist[i][j]=maxw;
		for(i=0;i<n;i++)
		{
			scanf("%d %d %d %d",&a[i],&b[i],&c[i],&m[i]);
			//dist[i][i]=0;
			for(j=0;j<m[i];j++)
			{
				scanf("%d %d",&to[i][j],&cost[i][j]);
				dist[i][to[i][j]]=cost[i][j];
			}
		}
		Floyd();
		memset(f,-1,sizeof(f));
		f[1][0][0]=a[0];ans=0;d--;
		for(i=2;i<=d;i++)
			for(j=0;j<n;j++)
			{
				for(k=0;k<n;k++)
				{
					if(dist[k][j]==maxw)continue;
					for(x=0;x<3;x++)
					{
						if(dist[k][j]<=f[i-1][k][x])
							checkmax(f[i][j][0],f[i-1][k][x]-dist[k][j]+a[j]);
					}
				}
				if(~f[i-1][j][2])checkmax(f[i][j][2],f[i-1][j][2]+c[j]);
				if(~f[i-1][j][1])checkmax(f[i][j][2],f[i-1][j][1]+c[j]);
				if(~f[i-1][j][0])checkmax(f[i][j][1],f[i-1][j][0]+b[j]);
			}
		for(i=0;i<n;i++)for(x=0;x<3;x++)checkmax(ans,f[d][i][x]);
		printf("%d\n",ans);
	}
	return 0;
}
示例#17
0
Grafo huries (Grafo G1, Grafo G2, Grafo G3, tPuente P[N], int nP, tCoste mCosViaje[][N])
{
    Grafo archipielago_huries;
    vertice mCam[N][N], or, dest;
    int i,j;
    
    
    archipielago_huries = CrearArchipielago(G1, G2, G3);
    
    //los puentes no tienen coste, luego los añadimos al grafo del archipielago
    for(i=0; i<nP; i++)
    {
        or=P[i].p1;
        dest=P[i].p2;
        archipielago_huries->Costes[or][dest] = 0;
    }
    
    //por fin, utilizamos Floyd
    Floyd(archipielago_huries, mCosViaje, mCam);
    
    return archipielago_huries;
}
示例#18
0
文件: 1596.cpp 项目: cpsa3/backup
int main ()
{
    int i,j,s,e;
    while(scanf("%d",&N)!=EOF)
    {
        memset(map,0,sizeof(map));
        for(i=1;i<=N;i++)
            for(j=1;j<=N;j++)
                scanf("%lf",&map[i][j]);
        Floyd();
        scanf("%d",&Q);
        for(i=1;i<=Q;i++)
        {
            scanf("%d%d",&s,&e);
            if(map[s][e]==0)
                printf("What a pity!\n");
            else
                printf("%.3lf\n",map[s][e]);
        }
    }
return 0;
}
示例#19
0
int main(void) {

   int p, my_rank, n;
   MPI_Comm comm;
   int* local_mat;
   int* temp_mat;
   MPI_Init(NULL, NULL);
   comm = MPI_COMM_WORLD;
   MPI_Comm_size(comm, &p);
   MPI_Comm_rank(comm, &my_rank);

   if (my_rank == 0) {
   
      printf("How many vertices?\n");
      scanf("%d", &n);
   }
   MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
   local_mat = malloc((n*n/p)*sizeof(int));
   
   if (my_rank == 0) {
   
      temp_mat = malloc((n*n)*sizeof(int));
      printf("Enter the matrix\n");
      Read_matrix(temp_mat, n);
   }
   MPI_Scatter(temp_mat, n*n/p, MPI_INT, local_mat, n*n/p, MPI_INT, 0, comm);
   Floyd(local_mat, my_rank, n, p);
   MPI_Gather(local_mat, n*n/p, MPI_INT, temp_mat, n*n/p, MPI_INT, 0, comm);
   free(local_mat);
   
   if (my_rank == 0) {
   
      printf("The solution is:\n");
      Print_matrix(temp_mat, n);
      free(temp_mat);
   }
   MPI_Finalize();
   return 0;
}  /* main */
示例#20
0
文件: Floyd.cpp 项目: wangchaohui/lib
int main()
{
	int i,j,a,b,c,m,mn;
	while(scanf("%d",&n)==1 && n)
	{
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)d[i][j]=-1;
			d[i][i]=0;
			scanf("%d",&j);
			while(j--)
			{
				scanf("%d %d",&a,&b);
				d[i][a]=b;
			}
		}
		memcpy(dist,d,sizeof(d));
		Floyd();
		m=200000000;
		for(i=1;i<=n;i++)
		{
			c=0;
			for(j=1;j<=n;j++)
			{
				if(dist[i][j]>c)c=dist[i][j];
				if(dist[i][j]==-1)break;
			}
			if(j!=n+1)continue;
			if(c<m)
			{
				m=c;
				mn=i;
			}
		}
		if(m==200000000)puts("disjoint");
		else printf("%d %d\n",mn,m);
	}
	return 0;
}
示例#21
0
文件: 1385.cpp 项目: Natureal/HDU
int main()
{
	int a,b,u;
	while(scanf("%d",&n)!=EOF && n)
	{
		init();
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				scanf("%d",&map[i][j]);
				if(map[i][j]==-1)
					map[i][j]=INF;
			}
		}
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&tax[i]);
		}
		Floyd();
		while(scanf("%d%d",&a,&b)!=EOF)
		{
			if(a==-1&&b==-1)break;
			u=a;
			printf("From %d to %d :\n",a,b);
			printf("Path: %d",a);
			while(u!=b)
			{
				printf("-->%d",path[u][b]);
				u=path[u][b];
			}
			puts("");
			printf("Total cost : %d\n\n",map[a][b]);
		}
	}
	return 0;
}
示例#22
0
int main()
{
    int i, j, a, b, c, st, et;
    while (~scanf("%d %d %d", &T, &S, &D))
    {
        memset(ss, false, sizeof(ss));
        memset(tt, false, sizeof(tt));
        memset(edge, INF, sizeof(edge));
        //memset(dist, INF, sizeof(dist));
        
        N = -1;
        for (i=1; i<=T; ++i)
        {
            scanf("%d %d %d", &a, &b, &c);
            if (c < edge[a][b])
                edge[a][b] = edge[b][a] = c;
            if (a>b && a>N)
                N = a;
            else if (b>a && b>N)
                N = b;
        }// Input
        for (i=1; i<=S; ++i)
        {
            scanf("%d", &st);
            ss[st] = true;
        }
        for (i=1; i<=D; ++i)
        {
            scanf("%d", &et);
            tt[et] = true;
        }// preprocess
        
        printf("%d\n", Floyd());
    }// end of while
    
    return 0;
}
示例#23
0
/*void printPath(int n)
{
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            printf("%d ", path[i][j]);
        }
        printf("\n");
    }
}*/
int main()
{
    int tN,n,r,d,s,t;
    scanf("%d",&tN);
    for (int i=0; i<tN; i++)
    {
        memset(path, 0, sizeof(path));
        scanf("%d",&n);
        getPath(n);
        //printPath(n);
        Floyd(n);
        //printPath(n);
        scanf("%d",&r);
        d=0;
        while (r--) 
        {
            scanf("%d %d", &s, &t);
            d+=path[s-1][t-1];
            //printf("d = %d\n",d);
        }
        printf("Case #%d: %d\n", i+1, d);
    }
    return 0;
}
示例#24
0
int AStarPathFind::PathFind(int nStartX, int nStartY, int nEndX, int nEndY, std::list<Point>& oListPath)
{
    if (m_poMapConf == NULL)
    {
        return -1;
    }
    nStartX = XMath::Max(0, XMath::Min(nStartX, (int)m_poMapConf->nPixelWidth - 1));
    nStartY = XMath::Max(0, XMath::Min(nStartY, (int)m_poMapConf->nPixelHeight - 1));
    nEndX = XMath::Max(0, XMath::Min(nEndX, (int)m_poMapConf->nPixelWidth - 1));
    nEndY = XMath::Max(0, XMath::Min(nEndY , (int)m_poMapConf->nPixelHeight - 1));
    int nSX = nStartX / gnUnitWidth;
    int nSY = nStartY / gnUnitHeight;
    int nEX = nEndX / gnUnitWidth;
    int nEY = nEndY / gnUnitHeight;
    if (nSX == nEX && nSY == nEY)
    {
        return -2;
    }
    if (!CanWalk(nSX, nSY) || !CanWalk(nEX, nEY))
    {
        return -3;
    }
    m_uSearchVersion++;
    ASTAR_NODE* pNode = GetNode(nSX, nSY);
    ASTAR_NODE* pEnd = GetNode(nEX, nEY);
    if (pNode == NULL || pEnd == NULL)
    {
        return -4;
    }
    m_OpenedList.Clear();
    pNode->bOpened = true;
    m_OpenedList.Push(pNode);
    static int tDir[8][2] = { { -1, 1 }, { -1, 0 }, { -1, -1 }, { 0, 1 }, { 0, -1 }, { 1, 1 }, { 1, 0 }, { 1, -1 } };
    while (!pEnd->bClosed && m_OpenedList.Size() > 0)
    {
        pNode = m_OpenedList.Min();
        m_OpenedList.Remove(pNode);
        pNode->bOpened = false;
        pNode->bClosed = true;
        ASTAR_NODE* pTmpNode = NULL;
        for (int i = 0; i < 8; i++)
        {
            int nX = pNode->nX + tDir[i][0];
            int nY = pNode->nY + tDir[i][1];
            pTmpNode = GetNode(nX, nY);
            if (pTmpNode == NULL || !CanWalk(nX, nY)) 
            {
                continue;
            }
            if (!CanDiagonalWalk(pNode, pTmpNode))
            {
                continue;
            }
            int nG = pNode->nG + GetG(pNode->nX, pNode->nY, pTmpNode->nX, pTmpNode->nY);
            int nH = GetH(pTmpNode->nX, pTmpNode->nY, pEnd->nX, pEnd->nY);
			int nF = nG + nH;
            if (pTmpNode->bOpened || pTmpNode->bClosed)
            {
                if (pTmpNode->nKey > nF)
                {
                    pTmpNode->nG = nG;
                    pTmpNode->nH = nH;
					pTmpNode->nKey = nF;
                    pTmpNode->pParent = pNode;
					if (pTmpNode->bOpened)
					{
						m_OpenedList.Update(pTmpNode);
					}
                }
            }
            else
            {
				pTmpNode->nG = nG;
                pTmpNode->nH = nH;
				pTmpNode->nKey = nF;
                pTmpNode->pParent = pNode;
                m_OpenedList.Push(pTmpNode);
                pTmpNode->bOpened = true;
            }
        }
    }
    if (!pEnd->bClosed)
    {
        return -5;
    }
    m_oTmpListPath.clear();
    ASTAR_NODE* pTarNode = pNode;
	//XLog(LEVEL_DEBUG,"Robot path0:");
    while (pTarNode != NULL)
    {
        ASTAR_POINT oASPos;
        oASPos.nX = pTarNode->nX;
        oASPos.nY = pTarNode->nY;
		//XLog(LEVEL_DEBUG, "[%d,%d] ", oASPos.nX, 35 - oASPos.nY);
        m_oTmpListPath.push_front(oASPos);
        pTarNode = pTarNode->pParent;
    }
	//XLog(LEVEL_DEBUG,"\n");

    if (m_oTmpListPath.size() > 2)
    {
        Floyd(m_oTmpListPath);
    }
    ASLITER iter = m_oTmpListPath.begin();
    ASLITER iter_end = m_oTmpListPath.end();
	//XLog(LEVEL_DEBUG,"Robot path1:");
    for (; iter != iter_end; iter++)
    {
        ASTAR_POINT& oPos = *iter;
		int nPosX = (int)((oPos.nX + 0.5f) * gnUnitWidth);
		int nPosY = (int)((oPos.nY + 0.5f) * gnUnitHeight);
		oListPath.push_back(Point(nPosX, nPosY));
		//XLog(LEVEL_DEBUG,"[%d,%d](%d,%d) ", nPosX, nPosY, oPos.nX, 35-oPos.nY);
    }
	//XLog(LEVEL_DEBUG,"\n");
    return 0;
}
示例#25
0
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "nodo.h"
#include "dijkstra.h"
#include "floyd.h"
#include "kruskal.h"
#include "QComboBox"
#include "QLabel"
#include "QString"

QLabel * label;
Dijkstra dijkstra = Dijkstra();
Floyd floyd = Floyd();
Kruskal kruskal = Kruskal();

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowTitle("Map Path Simulator");
    ui->mapa->setPixmap(QPixmap(":/Images/mapa.png"));
    layout = new QVBoxLayout(this);
    //for(int i = 0; i < 54; i++)
    //{
        //label = new QLabel("hola");
        //QString hola;
        //hola.append("hola");
        //label->setText(hola);
        //layout->addWidget(label);
    //}
示例#26
0
int main()
{
	s--; f--;
	vector<TrainLeg> AllTrain(read());//считывание xml файла
	//AllTrain[0].ShowAll();
	vector<int> arrayNumStantion(CountStantion(AllTrain));//массив всех доступных станций
	cout << "Stantion:";
	for (int i = 0; i < arrayNumStantion.size();++i)
	{
		cout<<arrayNumStantion[i]<<" ";
	}
	//
	float **graphCost = new float*[arrayNumStantion.size()];//матрица стоимости
	for (int count = 0; count < arrayNumStantion.size(); count++)
		graphCost[count] = new float[arrayNumStantion.size()]; 
	int **next = new int*[arrayNumStantion.size()];//массив предков для восстановления пути
	for (int count = 0; count < arrayNumStantion.size(); count++)
		next[count] = new int[arrayNumStantion.size()];

	//
	//инициализация максимумами
	for (int i = 0; i < arrayNumStantion.size(); ++i)
		for (int j = 0; j < arrayNumStantion.size(); ++j)
			graphCost[i][j] = MAX;

	//
	for (int i = 0; i < arrayNumStantion.size(); ++i)
		for (int j = 0; j < arrayNumStantion.size(); ++j)
		{
			next[i][j] = i;
			if (i == j)
			{
				graphCost[i][j] = 0;
				continue;
			}
			int ind = find_train_minprice(AllTrain, arrayNumStantion[i], arrayNumStantion[j]);
			if (ind != -1)
			{
				graphCost[i][j] = AllTrain[ind].getPrice();
				continue;
			}
		}
	//
	cout << endl<<endl<<endl;
	cout << "Initial Matrix: "<<endl;
	for (int i = 0; i < arrayNumStantion.size(); ++i,cout<<endl)
		for (int j = 0; j < arrayNumStantion.size(); ++j)
			cout << graphCost[i][j] << "\t";

	int n = arrayNumStantion.size();
	Floyd(graphCost, next, n);
	//
	cout << endl << endl << endl;
	if (graphCost[s][f] < MAX)
	{
		cout << "Way " << arrayNumStantion[f] << " -> " << arrayNumStantion[s]<<endl;
		cout<<"MIN Price = ";
		cout << graphCost[s][f] << endl;
		Travel(s, f, next);
		cout << "All way: ";
		for (int i = way.size()-1; i >=0 ; --i)
			cout <<arrayNumStantion[way[i]]<<" ";
	}
	else
	{
		cout << "Way " << arrayNumStantion[f] << " -> " << arrayNumStantion[s]<< "not found"<<endl;
	}
	//
	cout << endl << endl << endl;
	cout << "Matrix min price:" << endl;
	for (int i = 0; i < arrayNumStantion.size(); ++i, cout << endl)
		for (int j = 0; j < arrayNumStantion.size(); ++j)
			cout << graphCost[i][j] << "\t";
	system("pause");
	return 0;
}
示例#27
0
	void solve(void) {
		Input();
		Floyd();
		MakeGraph();
		printf("%lld\n", MinCost());
	}
示例#28
0
int main() {
    MGraph* g = new MGraph;
    createMGraph(g);
    Floyd(g);
}