void bfs(int y, int x)
{  
	q.push_back(make_pair(make_pair(y,x),0)); 
	v[y][x]=1;
	while(!q.empty())
	{
		int deqh=q.front().first.first;
		int deqw=q.front().first.second;
		int deqc=q.front().second;
		q.pop_front();
		for(int i=0;i<4;i++)
		{
			int nx=deqw+dx[i];
			int ny=deqh+dy[i];
			if(nx>=0&&nx<w&&ny>=0&&ny<h&&!v[ny][nx])
			{ 
				if(!arr[ny][nx]) 
					// 0을 모두 방문해야하니, 앞으로 넣어준다. 그래야 다음 deq값도 0이 나오기 때문.
				{
					q.push_front(make_pair(make_pair(ny,nx),deqc));
					arr2[ny][nx]=deqc; // 배열을 하나 더 써야 원본맵 정보가 섞이지 않는다.
					v[ny][nx]=1;
				}
				else // 벽에 막혀 못 가는 경우라면 뒤로 넣어준다. 그래야 그 값을 새로 열린 길이라 여기고 bfs하기 때문.
				{ 
					q.push_back(make_pair(make_pair(ny,nx),deqc+1));
					arr2[ny][nx]=deqc+1;
					v[ny][nx]=1;
				}
			}
		}
	}   
}
Example #2
0
int main()
{
	
	cout << "enter frame size";
	int n, i, s, fault = 1;
	cin >> n;
	int *arr = new int[n];
	cout << "enter elemnets" << endl;
	for (i = 0; i < n; i++)
		cin >> arr[i];
	cout << "enter page size" << endl;
	cin >> s;
	mem.push_back(arr[0]);
	for (i = 1; i < n; i++)
	{
		if (mem.size() == s)
		{
			int ex = found(arr[i]);
			if (ex == -1)
			{
				fault++;
				mem.pop_front();
				mem.push_back(arr[i]);
			}
		}
		else
		{
			fault++;
			mem.push_back(arr[i]);
		}
		
	}
	cout <<  "no of faults is" << fault;
    return 0;
}
Example #3
0
BackgroundDef BackgroundImpl::Layer::CreateRandomBGA( const Song *pSong, const RString &sEffect, deque<BackgroundDef> &RandomBGAnimations, Actor *pParent )
{
	if( g_RandomBackgroundMode == BGMODE_OFF )
		return BackgroundDef();

	// Set to not show any BGChanges, whether scripted or random
	if( GAMESTATE->m_SongOptions.GetCurrent().m_bStaticBackground )
		return BackgroundDef();

	if( RandomBGAnimations.empty() )
		return BackgroundDef();

	/* XXX: every time we fully loop, shuffle, so we don't play the same sequence
	 * over and over; and nudge the shuffle so the next one won't be a repeat */
	BackgroundDef bd = RandomBGAnimations.front();
	RandomBGAnimations.push_back( RandomBGAnimations.front() );
	RandomBGAnimations.pop_front();

	if( !sEffect.empty() )
		bd.m_sEffect = sEffect;

	map<BackgroundDef,Actor*>::const_iterator iter = m_BGAnimations.find( bd );

	// create the background if it's not already created
	if( iter == m_BGAnimations.end() )
	{
		bool bSuccess = CreateBackground( pSong, bd, pParent );
		ASSERT( bSuccess );	// we fed it valid files, so this shouldn't fail
	}
	return bd;
}
Example #4
0
File: T1053.cpp Project: DrhF/ACM
int main (void)
{
#ifndef ONLINE_JUDGE
	freopen ("T1053.in", "r", stdin);
	freopen ("T1053.out", "w", stdout);
#endif

	cin >> n;

	for (int i=1; i<=n; ++i)
	{
		int a;
		cin >> a; 
		v.push_back(a);
	}

	while (v.size()!=1)
	{
		v[1]=gcd(v[0], v[1]);
		v.pop_front();
	}

	cout << v[0];
	
	return 0;
}
Example #5
0
bool spfa() {
	dist[0] = 0;
	isInQ[0] = true;
	que.emplace_back(0);

	while (!que.empty()) {
		size_t here = que.front();
		que.pop_front();
		isInQ[here] = false;

		visits[here]++;
		if (visits[here] > n) return true;

		for (auto edge : G[here]) {
			int next = edge.second;
			int weight = edge.first;

			if (dist[next] > dist[here] + weight) {
				dist[next] = dist[here] + weight;

				if (isInQ[next] == false) {
					que.emplace_back(next);
					isInQ[next] = true;
				}
			}
		}
	}

	return false;
}
Example #6
0
int main()
{
	//freopen("input.txt","r",stdin);
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;++i) scanf("%d",s+i);
	if(k == 1)
	{
		printf("%d\n",n);
		return 0;
	}
	--k;
	SA();
//	for(int i=1;i<=n;++i) printf("%d\n",height[i]);
	int ans = 0;
	for(int i=1;i<=k;++i)
	{
		while(q.size() && q.back() > height[i]) q.pop_back();
		q.push_back(height[i]);
	}
	ans = q.front();
	for(int i=2,j=k+1;j<=n;++i,++j)
	{
		if(height[i-1] == q.front()) q.pop_front();
		while(q.size() && q.back() > height[j]) q.pop_back();
		q.push_back(height[j]);
		if(q.size()) ans = max(ans,q.front());
	}
	printf("%d\n",ans);
	return 0;
}
Example #7
0
void mythread_exit() {

    tcb *this_th = thread_list[this_th_th];
    while (!this_th->waiting.empty()) {
        queue.push_back(this_th->waiting.front());
        this_th->waiting.pop_front();
    }
    deque<tcb*>::iterator it = find(queue.begin(), queue.end(), this_th);
    if (it != queue.end())
        queue.erase(it, it+1);
    if (queue.empty()) {
        exit(0); // no other thread remaining
    }
    // run the next thread if availiable
    tcb *  thread = queue.front();
    queue.pop_front();

    tcb *th = thread_list[this_th_th];
    delete th;
    thread_list.erase(this_th_th);



    this_th_th = thread->id;


    setcontext(&(thread->context));
    

    }
Example #8
0
  int sub(deque<pair<int,pair<long long, long long> > > price_and_mask, long long signature, int sum) {//, int cut=0) {
	int size = price_and_mask.size();
	if (size == 0) return 0;
	if (size == 1) return -(price_and_mask.front().first);
	if (m.find( signature ) != m.end()) return m[ signature ];
	
	long long sold_out = price_and_mask.front().second.second;
	//	vector< pair<int,long long> > price_sub1;
	deque< pair<int,pair<long long, long long> > > price_sub1;
	long long new_signature = 0;
	int sum1 = 0;
	tr(price_and_mask,it) {
	  if ((sold_out & it->second.second) == 0) {
		price_sub1.push_back( *it );
		new_signature |= it->second.first;
		sum1 -= it->first;
	  }
	}
	int amount1 = - price_and_mask.front().first + sub(price_sub1, new_signature, sum1);

	sum -= price_and_mask.front().first;
	if (sum < amount1) {
	  m[ signature ] = amount1;
	  return amount1;
	} 

	new_signature = signature - price_and_mask.front().second.first;
	price_and_mask.pop_front();

	int amount = max(amount1, sub(price_and_mask, new_signature, sum));
	m[ signature ] = amount;
	return amount;
  }
Example #9
0
int main(int argc, char *argv[])
{
    for (int i=0;i<size;i++)
    {
        cin>>frequency[i];                  //?入10??值
        ptr=new node;
        ptr->key=frequency[i];
        ptr->lchild=NULL;
        ptr->rchild=NULL;
        forest.push_back(ptr);
    }//形成森林,森林中的每一棵?都是一???
 
    //?森林?建霍夫曼?
    for (int i=0;i<size-1;i++)
    {
                sort(forest.begin(),forest.end(),compare);
                ptr=new node;
                //以下代?使用下?索引?列元素,具有?在危?,使用??注意
                ptr->key=forest[0]->key+forest[1]->key;
                ptr->lchild=forest[0];
                ptr->rchild=forest[1];
                forest.pop_front();
                forest.pop_front();
                forest.push_back(ptr);
        }
    ptr=forest.front();//ptr是一?指向根的指?
    printCode(code);
    //system("pause");
   
    while (1);
    return EXIT_SUCCESS;
}
Example #10
0
inline void operation(deque<string> &operationDeque, map<string, bool> &visitedMap, string &goalMatrix, int maxDepth) {

    while (true) {
        string currentMatrix = operationDeque.front();
        operationDeque.pop_front();
        if (currentMatrix.length() > MATRIX_SIZE + maxDepth) {
            cout << "-1" << endl;
            return;
        }

        if (currentMatrix.find(goalMatrix) != string::npos) {
            if (currentMatrix.length() == MATRIX_SIZE) {
                cout << "0 " << endl;
                return;
            }

            string answer = currentMatrix.substr(MATRIX_SIZE);
            cout << answer.length() << " " << answer << endl;
            return;
        }
        AOperation(operationDeque, visitedMap, currentMatrix);
        BOperation(operationDeque, visitedMap, currentMatrix);
        COperation(operationDeque, visitedMap, currentMatrix);
    }
}
Example #11
0
void vecDiff(const deque<unsigned int>& first, const deque<unsigned int>& second, deque<unsigned int>& result){

  result.clear();
  /* Assumption: the first argument is larger than the second one */
  int carry = 0;
  bool finished = false;
  deque<unsigned int>::const_reverse_iterator secondItr = second.rbegin(), secondItrEnd = second.rend();
  for (deque<unsigned int>::const_reverse_iterator itr = first.rbegin(), endItr = first.rend(); itr != endItr; itr++){
    int sec  = 0;
    if(secondItr != secondItrEnd){
      sec = *secondItr;
      secondItr++;
    }
    int sub =  carry + sec;
    if (*itr >= sub){
      result.push_front(*itr - sub);
      carry = 0;
    }

    else {
      result.push_front(*itr + 10 - sub);
      carry = 1;
    }
  }
  
  while (!result.empty() && result.front() == 0)
    result.pop_front();

  if (result.empty())
    result.push_back(0);
}
	void print(deque<double>& q1, deque<double>& q2) {
		double t1=q1.back();
		while (t1-q2.front()>1) q2.pop_front();
		for (int i=0; i<q2.size(); i++) {
			cout << q2[i] << " " << t1 << endl;
		}
	}
Example #13
0
void dfs(int v) {

    vector<int> l1, l2;
    while (dq.size() and deep[dq.back()] < deep[v]) {
        l1.PB(dq.back());
        dq.pop_back();
    }
    dq.push_back(v);
    ans[v] = dq[0];
    //cout << v << ' ' << dq[0] << endl;
    for (auto x: el[v]) {
        while (dq.size() and deep[dq[0]] < x) {
            l2.PB(dq[0]);
            dq.pop_front();
        }
        dfs(x);
        while (l2.size()) {
            dq.push_front(l2.back());
            l2.pop_back();
        }
    }
    dq.pop_back();
    while (l1.size()) {
        dq.push_back(l1.back());
        l1.pop_back();
    }
}
Example #14
0
void CcModelDonut::ParseInput(deque<string> &  tokenList)
{
//        string theString;
//Just read ID, LABEL,
// IX, IY, IZ,
// RED, GREEN, BLUE,
// OCC*1000,
// COVRAD, VDWRAD, SPARERAD
// FLAG,
// UISO or X11
      id        = atoi ( tokenList[0].c_str() );
      m_label     =        string(tokenList[1]);    //LABEL
      x         = atoi ( tokenList[2].c_str() );
      y         = atoi ( tokenList[3].c_str() );
      z         = atoi ( tokenList[4].c_str() );
      r         = atoi ( tokenList[5].c_str() );
      g         = atoi ( tokenList[6].c_str() );
      b         = atoi ( tokenList[7].c_str() );
      occ       = atoi ( tokenList[8].c_str() );
      covrad    = atoi ( tokenList[9].c_str() );
      vdwrad    = atoi ( tokenList[10].c_str() );
      sparerad  = atoi ( tokenList[11].c_str() );
      x11       = atoi ( tokenList[12].c_str() );
      rad       = atoi ( tokenList[13].c_str() );
      dec       = atoi ( tokenList[14].c_str() );
      az        = atoi ( tokenList[15].c_str() );
      for ( int i = 0; i<16; i++ ) tokenList.pop_front();
}
Example #15
0
int SPFA(int s,int t)
{
    Q.clear();
    Q.push_back(s);
    memset(visit,127,sizeof(visit));
    memset(use,false,sizeof(use));
    use[s] = true;
    visit[s] = 0;
    while (!Q.empty())
    {
        int now = Q.front();
        Q.pop_front();
        use[now] = false;
        if (now == t)   return visit[now];
        for (int i = 1;i <= 100;i++)
        if (visit[now]+map[now][i] < visit[i])
        {
            visit[i] = visit[now]+map[now][i];
            if (use[i] == false)
            {
                Q.push_back(i);
            }
        }
    }
}
Example #16
0
 void GetAllPath(string& start, string& end, unordered_map<string, list<string> >& DirGraph) {
     if(start == end) {
         oneSol.push_front(end);
         sols.push_back(vector<string>());
         copy(oneSol.begin(), oneSol.end(), back_inserter(sols.back()));
         oneSol.pop_front();
         return;
     }
     
     unordered_map<string, list<string> >::iterator it = DirGraph.find(start);
     oneSol.push_front(start);
     for(list<string>::iterator lit = it->second.begin(); lit != it->second.end(); ++lit)
             GetAllPath(*lit, end, DirGraph);
     oneSol.pop_front();
     
 }
Example #17
0
void merge (int v, const edge &u)
{
  cvar (v), evar (u.t);
  now.resize (height[u.t] + 1);
  fill (iter (now), MKP (-oo, 0));
  dfs_sbtr (u.t, 0, 1, u.w >= lmt ? 1 : -1);

  Q.clear ();
  for (int i = min (height[u.t], R), j = 0; i; --i)
    {
      for (; j < sz_m (vec) && i + j <= R; ++j)
        {
          for (; !Q.empty () && Q.back ().Py.Px < vec[j].Px; Q.pop_back ());
          Q.push_back (MKP (j, vec[j]));
        }
      while (!Q.empty () && Q.front ().Px + i < L)
        Q.pop_front ();

      // match now[i] && Q.front ()
      if (!Q.empty () && now[i].Px + Q.front ().Py.Px >= 0)
        ans = MKP (now[i].Py, Q.front ().Py.Py); //, cerr << "upd: " << ans.Px << " " << ans.Py << endl;
    }

  for (int i = 1; i <= height[u.t]; ++i)
    if (sz_m (vec) <= i)
      vec.push_back (now[i]);
    else
      chkmax (vec[i], now[i]);
}
Example #18
0
bool BFS(int t[MAX][MAX]) {
  fifo.clear();
  fifo.push_back(SOURCE);
  vert.clear();
  for (int i=1; i<=n; i++) prev[i]=0; 
  prev[SOURCE] = SOURCE;
  bool test = true;
  while (test && (!fifo.empty())) {
    int c = fifo.front();
    for (int i=1; i<=n; i++) {
      if ((prev[i]==0) && (t[c][i]!=0)) {
	fifo.push_back(i);
	prev[i] = c;
	if (i==SINK) {
	  test = false;
	  break;
	}
      }
    }
    fifo.pop_front();
  }
  if (test) return false;
  else {
    int c = SINK;
    vert.push_front(c);
    while (c != SOURCE) {
      c = prev[c];
      vert.push_front(c);
    } 
    return true;
  }
}
// void solve(int N, int M, int s, int A[]){
void solve(){
	pii cur;
	int dog, m;

	q.push_back(mp(s,0));
	while(!q.empty()){
		cur = q.front();
		q.pop_front();
		dog = cur.first;
		m = cur.second;
		// cout << "DOG: " << dog << " turn: " << m;
		if (m == M){
			f[dog] += 1;
		}else if(m < M){
			if (dog+A[m] <= N){

				q.push_back(mp(dog+A[m], m+1));
				// cout << "Appending dog: " << dog+A[m] << " ";
			}
			if (dog-A[m] > 0){
				q.push_back(mp(dog-A[m], m+1));
				// cout << "Appending dog : " << dog-A[m] << " ";
			}
		}
		// cout << endl;
	}
	for (int i = 1; i <= N; i += 1){
		cout << f[i] << " ";
	}
	cout << endl;
}
void ofxBlobTracker::draw(float x,float y,float w, float h) {
	// stroked rect
	ofEnableAlphaBlending();
	ofSetColor(0, 0, 0, 70);
	ofRect(x, y, w, h);
	ofSetHexColor(0xFFFFFF);
	
	ofNoFill();
	ofRect(x, y, w, h);
	
	glPushMatrix();
	glTranslatef(x, y, 0);
	ofSetColor(0,150, 0);
	
	map<int,ofVec3f>::iterator it;
	for(it = smoothedBlobs.begin(); it!=smoothedBlobs.end(); it++) {
		ofCircle((*it).second.x*w, (*it).second.y*h, 5);
		ofDrawBitmapString("id: "+ofToString((*it).first), (*it).second.x*w, (*it).second.y*h);
		blobStore.push_back((*it).second);
	}

	while(blobStore.size()>50) {
		blobStore.pop_front();
	}
	deque<ofVec2f>::iterator itr;
	for(itr = blobStore.begin(); itr!=blobStore.end(); itr++) {
		ofCircle((*itr).x*w,(*itr).y*h, 5);
	}
	glPopMatrix();
	ofFill();
	
}
Example #21
0
File: 1123.cpp Project: bzz13/timus
void resolve(deque<char>& q, deque<char>& s)
{
	int tmp;
	deque<char> replaced;
	do
	{
		if (q.size() > 0)
		{
			tmp = q.back() - '0' + 1;
			q.pop_back();
			s.pop_front();
		}
		else
			tmp = '0';

		if (tmp > 9)
			replaced.push_front('0');
		else
		{
			replaced.push_front(tmp + '0');
			break;
		}
	} while (true);

	while (replaced.size() > 0)
	{
		tmp = replaced.front();
		q.push_back(tmp);
		s.push_front(tmp);
		replaced.pop_front();
	}
}
Example #22
0
void send_th ()
{
	ServerSocket w_server ( 30001 );
	ServerSocket w_sock;
	w_server.accept ( w_sock );

	cout << "Reader connacted" << endl;

	while (active)
	{
		// queue_mutex.lock();
		while (queue.size() > 0)
		{
			ticket *task;
			task = queue.front();
			queue.pop_front();

			try
			{
				w_sock << task;
				cout << "send to 30001\n";
			} catch (SocketException& e) {
				cout << e.description() << endl;
			}
		}
		// queue_mutex.unlock();

		// usleep(50000);
	}
}
Example #23
0
bool Bellman_Ford()
{
  int i , x , y , z;
  memset(f , 0 , sizeof(f));
  for (i = 1; i <= t ; ++ i) d[i] = 1 << 30;
  d[s] = 0 , f[s] = 1 , q.push_back(s);
  while (!q.empty())
  {
    x = q.front() , q.pop_front() , f[x] = 0;
    for (i = pre[x] ; ~i ; i = e[i].next)
    {
      y = e[i].x , z = e[i].c;
      if (e[i].f && d[y] > d[x] + z)
      {
        d[y] = d[x] + z , p[y] = i;
        if (!f[y])
        {
          if (q.empty() || d[y] < d[q.front()])
            q.push_front(y);
          else q.push_back(y);
          f[y] = 1;
        }
      }
    }
  }
  return d[t] != 1 << 30;
}
Example #24
0
int main(){
	scanf("%d %d",&n,&l);
	for (int i=0; i<n; i++) {
		scanf("%d %d",&a[i].first, &a[i].second);
		a[i].second = abs(a[i].second);
	}
	sort(a, a+n);
	for (int i=0; i<n; ) {
		int e = i;
		while(e < n && a[e].first == a[i].first) e++;
		while (stk.size() >= 2 && cross(stk[stk.size()-2], stk.back()) > cross(stk.back(), a[i])) {
			stk.pop_back();
		}
		stk.push_back(a[i]);
		i = e;
	}
	double ret = 0;
	while(stk.size() >= 2 && cross(stk[0], stk[1]) < 0) stk.pop_front();
	while(stk.size() >= 2 && cross(stk[stk.size()-2], stk.back()) > l) stk.pop_back();
	ret = max(ret, solve(0, cross(stk[0], stk[1]), stk[0]));
	ret = max(ret, solve(cross(stk[stk.size()-2], stk.back()), l, stk.back()));
	for(int i=1; i+1<stk.size(); i++){
		ret = max(ret, solve(cross(stk[i-1], stk[i]), cross(stk[i], stk[i+1]), stk[i]));
	}
	printf("%lf",ret);
}
/** Attempt to merge the paths specified in mergeQ with path.
 * @return the number of paths merged
 */
static unsigned mergePaths(const Lengths& lengths,
		ContigPath& path,
		deque<ContigNode>& mergeQ, set<ContigNode>& seen,
		const ContigPathMap& paths)
{
	unsigned merged = 0;
	deque<ContigNode> invalid;
	for (ContigNode pivot; !mergeQ.empty(); mergeQ.pop_front()) {
		pivot = mergeQ.front();
		ContigPathMap::const_iterator path2It
			= paths.find(pivot.contigIndex());
		if (path2It == paths.end())
			continue;

		ContigPath path2 = path2It->second;
		if (pivot.sense())
			reverseComplement(path2.begin(), path2.end());
		ContigPath consensus = align(lengths, path, path2, pivot);
		if (consensus.empty()) {
			invalid.push_back(pivot);
			continue;
		}

		appendToMergeQ(mergeQ, seen, path2);
		path.swap(consensus);
		if (gDebugPrint)
#pragma omp critical(cout)
			cout << get(g_contigNames, pivot)
				<< '\t' << path2 << '\n'
				<< '\t' << path << '\n';
		merged++;
	}
	mergeQ.swap(invalid);
	return merged;
}
Example #26
0
bool spfa(int st)
{
    for (int i=0;i<=V;i++)
    {
        dist[i] = INF;
    }
    dist[st] = 0;
    visited[st] = true;
    pqu.push_front(st);
    while(!pqu.empty()){
        int now = pqu.front();
        pqu.pop_front();
        visited[now] = false;
        for (int nt = first[now];nt!=0;nt = edges[nt].next){
            if (edges[nt].d + dist[now] < dist[edges[nt].y] ) {
                dist[edges[nt].y] =  edges[nt].d + dist[now];
                last[edges[nt].y] = now;
                if (!visited[edges[nt].y]){
                    visited[edges[nt].y] = true;
                    cnt[edges[nt].y]++;
                    if (cnt[edges[nt].y]>V) return false;
                    if (!pqu.empty()){
                        if (dist[edges[nt].y]>dist[pqu.front()])
                            pqu.push_back(edges[nt].y);
                        else
                            pqu.push_front(edges[nt].y);
                    } else pqu.push_front(edges[nt].y);
                }
            }
        }
    }
    return true;
}
Example #27
0
void Worker::_processFiles(){
      using namespace boost::filesystem;
      rx.clear();
      path current_dir(folderToProcess); //
	  vector<string> filesToScan;
	  for (recursive_directory_iterator iter(current_dir), end;	iter != end; ++iter){
		if( boost::filesystem::is_regular_file( iter->path() ))
			filesToScan.push_back(iter->path().c_str());
		}
	  
		for(size_t i = 0; i < filesToScan.size(); i++) {
		  string s = filesToScan[i];
		  double progress = i;
		  progress /= filesToScan.size();
		  showProgress(s, progress);
		  tx.push_back("scanfile \""+s+"\"\n");
		  while( rx.size() == 0 )
			Glib::usleep(10000);
		  string str = rx.front();
		  rx.pop_front();
		  //std::cout << "RX: "<< str << endl;
			
		}	  
		showProgress("Done",1);
}
// this function changes the community sizes merging the smallest communities
int change_community_size(deque<int> &seq) {

	
			
	if (seq.size()<=2)
		return -1;
	
	int min1=0;
	int min2=0;
	
	for (int i=0; i<seq.size(); i++)		
		if (seq[i]<=seq[min1])
			min1=i;
	
	if (min1==0)
		min2=1;
	
	for (int i=0; i<seq.size(); i++)		
		if (seq[i]<=seq[min2] && seq[i]>seq[min1])
			min2=i;
	

	
	seq[min1]+=seq[min2];
	
	int c=seq[0];
	seq[0]=seq[min2];
	seq[min2]=c;
	seq.pop_front();
	
	
	return 0;
}
Example #29
0
 void tranverseTree(TreeNode* root, deque<TreeNode*>& tranverseTwo, deque<TreeNode*>& swapNodes)
 {
     if(root == NULL)
       return;
     tranverseTree(root->left, tranverseTwo, swapNodes);
     if(tranverseTwo.size() < 1)
     {
         tranverseTwo.push_back(root); 
     }
     else
     {
         tranverseTwo.push_back(root);
         if(swapNodes.size() == 0)
         {
             if(tranverseTwo.front()->val > tranverseTwo.back()->val)
             {
                 swapNodes.push_back(tranverseTwo.front());
                 swapNodes.push_back(tranverseTwo.back());
             }
         }
         else
         {
             if(tranverseTwo.front()->val > tranverseTwo.back()->val)
                 swapNodes.back() = tranverseTwo.back();
         }
         tranverseTwo.pop_front();
     }
     tranverseTree(root->right, tranverseTwo, swapNodes);
 }
Example #30
0
bool Modlabel(int src, int des, int n) {
    int i, j, u, v, c, w, del;
    memset(dist, 0x3f, sizeof(dist[0])*(n + 3));
    dist[src] = 0;
    while(!Q.empty()) Q.pop_back();
    Q.push_back(src);
    while(!Q.empty()) {
        u = Q.front(); Q.pop_front();
        for(j = last[u]; j != -1; j = e[j].next) {
            v = e[j].v; c = e[j].c; w = e[j].w;
            if(c && (del = dist[u] + w) < dist[v]) {
                dist[v] = del;
                if(Q.empty() || del <= dist[Q.front()]) {
                    Q.push_front(v);
                }
                else {
                    Q.push_back(v);
                }
            }
        }
    }
    for(i = 0; i < n; i++) {
        for(j = last[i]; j != -1; j = e[j].next) {
            e[j].w -= dist[e[j].v] - dist[i];
        }
    }
    value += dist[des];
    return dist[des] < MOD;
}