Beispiel #1
0
int main(){
  int j,fa[4001],sec=INF,sectemp=INF,temp,n=scan(),i=n;
  init();  
  dj(n);
  for(j=0;j<=n;j++)fa[j]=father[j];
  init();
  do{
    temp=value[i][fa[i]];
    value[i][fa[i]]=INF;
    value[fa[i]][i]=INF;
    sectemp=dj(n);
    init();
    if(sectemp<sec)sec=sectemp;
    value[i][fa[i]]=temp;
    value[fa[i]][i]=temp;
    i=fa[i];
  }while(fa[i]!=0);
  printf("%d",sec);
  return 0;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    setIO("sample");
    n = gi;int m=gi;
    for(int i = 1,u,v,w;i<=m;++i)u=gi,v=gi,w=gi,addedge(u,v,w);
    dj(1,ds,ss,qs);
    dj(n,dt,st,qt);
    for(int i = 1;i<n;++i)
     for(int j = hd[i];j;j=e[j].ne){
     int k = e[j].v;
      if(dt[k]+e[j].w == dt[i]){
       fa[i] = k,e[j].fl = true;
       addedge2(k,i);break;
      }
     }
    static int qu[MN],bot;
    qu[bot=1]=n;
    for(int i = 1;i<=bot;++i){
     int x = qu[i];
     for(int j = hd2[x];j;j=e2[j].ne) qu[++bot]=e2[j].v;
    }
    for(int i = 1;i<=bot;++i){
     int x = qu[i];
     if(ds[x]+dt[x] == ds[n]) prt[x] = x;
     else prt[x] = prt[fa[x]];
    }
    int ans = INF;
    for(int i = 1;i<=tot;++i){
     if(e[i].fl || ds[e[i].u]+e[i].w+dt[e[i].v]==ds[n])continue;
     int u = prt[e[i].u],v = prt[e[i].v];
     if(!u || !v || u==v || ds[u] > ds[v]) continue;
     int tmp = ds[e[i].u]+e[i].w+dt[e[i].v];
     ans = min(ans,tmp);
    }
    if(ans == INF )puts("-1");
    else printf("%d\n",ans);
    closeIO();
    return EXIT_SUCCESS;
}
Beispiel #3
0
int main()
{
       int start;
       printf("\nDIJKSTRA ALGORITHM");
       readgraph();
       displaymat();
       inittable();
       printf("\nEnter the starting Vertex:");
       scanf("%d",&start);
       dj(start);
       printf("\nfinal:");
       displaytable();
       getch();
       return 0;
}
Beispiel #4
0
void
Assembly::addJacobianBlock(SparseMatrix<Number> & jacobian, DenseMatrix<Number> & jac_block, const std::vector<dof_id_type> & idof_indices, const std::vector<dof_id_type> & jdof_indices, Real scaling_factor)
{
  if ((idof_indices.size() > 0) && (jdof_indices.size() > 0) && jac_block.n() && jac_block.m())
  {
    std::vector<dof_id_type> di(idof_indices);
    std::vector<dof_id_type> dj(jdof_indices);
    _dof_map.constrain_element_matrix(jac_block, di, dj, false);

    if (scaling_factor != 1.0)
    {
      _tmp_Ke = jac_block;
      _tmp_Ke *= scaling_factor;
      jacobian.add_matrix(_tmp_Ke, di, dj);
    }
    else
      jacobian.add_matrix(jac_block, di, dj);
  }
}
Beispiel #5
0
void
Assembly::cacheJacobianBlock(DenseMatrix<Number> & jac_block, std::vector<dof_id_type> & idof_indices, std::vector<dof_id_type> & jdof_indices, Real scaling_factor)
{
  if ((idof_indices.size() > 0) && (jdof_indices.size() > 0) && jac_block.n() && jac_block.m())
  {
    std::vector<dof_id_type> di(idof_indices);
    std::vector<dof_id_type> dj(jdof_indices);
    _dof_map.constrain_element_matrix(jac_block, di, dj, false);

    if (scaling_factor != 1.0)
    {
      _tmp_Ke = jac_block;
      _tmp_Ke *= scaling_factor;

      for(unsigned int i=0; i<di.size(); i++)
        for(unsigned int j=0; j<dj.size(); j++)
        {
          _cached_jacobian_values.push_back(_tmp_Ke(i, j));
          _cached_jacobian_rows.push_back(di[i]);
          _cached_jacobian_cols.push_back(dj[j]);
        }
    }
    else
    {
      for(unsigned int i=0; i<di.size(); i++)
        for(unsigned int j=0; j<dj.size(); j++)
        {
          _cached_jacobian_values.push_back(jac_block(i, j));
          _cached_jacobian_rows.push_back(di[i]);
          _cached_jacobian_cols.push_back(dj[j]);
        }
    }
  }

  jac_block.zero();
}
Beispiel #6
0
int SSL_SOCKET :: s_recv(char* b,int sz)
	{
	SecPkgContext_StreamSizes Sizes;
	SECURITY_STATUS ss = 0;
	ss = QueryContextAttributes(&hCtx,SECPKG_ATTR_STREAM_SIZES,&Sizes);
	if (FAILED(ss))
		return -1;

	int TotalR = 0;
	int pI = 0;
	SecBuffer Buffers[5] = {0};
	SecBuffer *     pDataBuffer;
	SecBuffer *     pExtraBuffer;
	Z<char> mmsg(Sizes.cbMaximumMessage*10);


	if (PendingRecvDataSize)
		{
		if (sz <= PendingRecvDataSize)
			{
			memcpy(b,PendingRecvData,sz);
			
			// 
			Z<char> dj(PendingRecvDataSize);
			memcpy(dj,PendingRecvData,PendingRecvDataSize);
			memcpy(PendingRecvData,dj + sz,PendingRecvDataSize - sz);
			PendingRecvDataSize -= sz;
			return sz;
			}
		// else , occupied already
		memcpy(b,PendingRecvData,PendingRecvDataSize);
		sz = PendingRecvDataSize;
		PendingRecvDataSize = 0;
		return sz;
		}

	for(;;)
		{
		unsigned int dwMessage = Sizes.cbMaximumMessage;
		
		if (dwMessage > Sizes.cbMaximumMessage)
			dwMessage = Sizes.cbMaximumMessage;

		int rval = 0;
		if (ExtraDataSize)
			{
			memcpy(mmsg + pI,ExtraData,ExtraDataSize);
			pI += ExtraDataSize;
			ExtraDataSize = 0;
			}
		else
			{
			rval = recv_p(mmsg + pI,dwMessage);
			if (rval == 0 || rval == -1)
				return rval;
			pI += rval;
			}


		Buffers[0].pvBuffer     = mmsg;
		Buffers[0].cbBuffer     = pI;
		Buffers[0].BufferType   = SECBUFFER_DATA;

		Buffers[1].BufferType   = SECBUFFER_EMPTY;
		Buffers[2].BufferType   = SECBUFFER_EMPTY;
		Buffers[3].BufferType   = SECBUFFER_EMPTY;

		sbin.ulVersion = SECBUFFER_VERSION;
		sbin.pBuffers = Buffers;
		sbin.cBuffers = 4;

		ss = DecryptMessage(&hCtx,&sbin,0,NULL);
		if (ss == SEC_E_INCOMPLETE_MESSAGE)
			continue;
		if (ss != SEC_E_OK && ss != SEC_I_RENEGOTIATE && ss != SEC_I_CONTEXT_EXPIRED)
			return -1;

		pDataBuffer  = NULL;
		pExtraBuffer = NULL;
		for (int i = 0; i < 4; i++) 
			{
			if (pDataBuffer == NULL && Buffers[i].BufferType == SECBUFFER_DATA) 
				{
				pDataBuffer = &Buffers[i];
				}
			if (pExtraBuffer == NULL && Buffers[i].BufferType == SECBUFFER_EXTRA) 
				{
				pExtraBuffer = &Buffers[i];
				}
			}
		if (pExtraBuffer)
			{
			ExtraDataSize = pExtraBuffer->cbBuffer;
			ExtraData.Resize(ExtraDataSize + 10);
			memcpy(ExtraData,pExtraBuffer->pvBuffer,ExtraDataSize);
			pI = 0;
			}

		if (ss == SEC_I_RENEGOTIATE)
			{
			ss = ClientLoop();
			if (FAILED(ss))
				return -1;
			}

	

		if (pDataBuffer == 0)
			break;

		TotalR = pDataBuffer->cbBuffer;
		if (TotalR <= sz)
			{
			memcpy(b,pDataBuffer->pvBuffer,TotalR);
			}
		else
			{
			TotalR = sz;
			memcpy(b,pDataBuffer->pvBuffer,TotalR);
			PendingRecvDataSize = pDataBuffer->cbBuffer - TotalR;
			PendingRecvData.Resize(PendingRecvDataSize + 100);
			PendingRecvData.clear();
			memcpy(PendingRecvData,(char*)pDataBuffer->pvBuffer + TotalR,PendingRecvDataSize);
			}


		break;
		}



	return TotalR;
	}