int BFS()
{
    while (!q.empty())
    {
        auto u = q.front();
        q.pop();
        for (int i = 0; i < 4; i++)
        {
            pair<int, int> v = make_pair(u.first + d_dist[i].first, u.second + d_dist[i].second);
            if(v.first < 0 || v.first >= 2000 || v.second < 0 || v.second >= 2000)
                continue;
            if (dist[v.first][v.second] == -1)
            {
                dist[v.first][v.second] = dist[u.first][u.second] + 1;
                if (mark[v.first][v.second])
                    return dist[v.first][v.second];
                q.push(v);
            }
        }
    }
    return 0;
}
Beispiel #2
0
void *ReceiveThread(void *)
#endif
{
	char buf[10000];
	while (true) {
		fgets(buf, 10000, stdin);
		buf[strlen(buf) - 1] = 0; // 改行コードを消す。

		if (strncmp(buf, "quit", strlen("quit")) == 0) {
			while (commandQueue.size() > 0) {
				// エンジン設定ダイアログでOKを押すと、setoptionとquitが続けて送られてくる。
				// その時、setoptionの内容を実行する前にexit()を呼ばないよう、quitコマンドより
				// 前に受信したコマンドが全て実行されてから終了するようにする。
				// 本当は、commandQueueのサイズが0だからといって、それ以前のコマンドが本当に
				// 実行されたという保証はないが(popしただけで、まだ実行前の可能性もあるので)、
				// setoptionに関しては実行に200msもかかることはないので、この対策だけで済ませる
				// ことにする。
				Sleep(200);
			}
			// 終了前にクリティカルセクションオブジェクトを破棄。
			DeleteCriticalSection(&cs);
			// quitを受信したらエンジンを終了する。
			exit(0);
		}
		EnterCriticalSection(&cs); // クリティカルセクションに入る。
		if (strncmp(buf, "stop", strlen("stop")) == 0) {
			isStopReceived = true;
		}
		if (strncmp(buf, "ponderhit", strlen("ponderhit")) == 0) {
			ponderhitReceiveTime = timeGetTime();
		}
		if (strncmp(buf, "gameover", strlen("gameover")) == 0) {
			isStopReceived = true; // 先読み中にgameoverが送られてきた場合、すぐ思考を打ち切る。
		}
		string commandStr = buf;
		commandQueue.push(commandStr); // コマンドをキューに追加。
		LeaveCriticalSection(&cs); // クリティカルセクションを出る。
	}
}
Beispiel #3
0
void spfa()
{
	while (!Q.empty())
	{
		int u = Q.front()&((1<<MAX)-1), st = Q.front()>>MAX;
		Q.pop();
		inq[u][st] = 0;
		for (int i = head[u]; i != -1; i = next[i])
		{
			int nst = st|bit[v[i]];
			if (d[u][st]+w[i] < d[v[i]][nst])
			{
				d[v[i]][nst] = d[u][st]+w[i];
				if (nst == st && !inq[v[i]][nst])
				{
					Q.push(nst<<MAX|v[i]);
					inq[v[i]][nst] = 1;
				}
			}
		}
	}
}
Beispiel #4
0
int main() {
#   ifdef _DEBUG
        freopen("i.in", "r", stdin);
#   else
        freopen("i.in", "r", stdin);
        freopen("i.out", "w", stdout);
#   endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    words.reserve(20000);
    int i;
    string s;
    while (cin >> s) {
        if (s == "<text>") {
            q.push((lastMap = new Memory));
            if (q.size() > 7) {
                Memory* toDel = q.front();
                for (i = 0; i < (int)words.size(); i++)
                    sevenDaysMap.words[i].count -= toDel->words[i].count;
                q.pop();
            }
            while (cin >> s, s != "</text>") {
                if (s.length() < 4)
                    continue;
                map<string, int>::iterator lb = wordMap.lower_bound(s);
                int id;
                if (lb != wordMap.end() && !wordMap.key_comp()(s, lb->first)) {
                    //existing.
                    id = lb->second;
                } else {
                    //new.
                    id = words.size();
                    wordMap.insert(lb, make_pair(s, id));
                    words.push_back(s);
                }
                lastMap->words[id].count++;
                sevenDaysMap.words[id].count++;
            }
        } else if (s == "<top") {
Beispiel #5
0
void make_snake(vector<Cor> &snake,int pos,int cost){
	if(pos>=snake.size()){
		if(!Done.count(snake)){
			Done.insert(snake);
			if(check(snake,snake.size()-1))
				Q.push(state(snake,cost));
		}
		return;
	}

	for(int r=0;r<6;r++){
		snake[pos].x+=dx[r]; snake[pos].y+=dy[r];
		if(!Rock.count(snake[pos])){
			if(pos+1>=snake.size() || is_next(snake[pos],snake[pos+1]) )
				if(check(snake,pos) )
					make_snake(snake,pos+2,cost);
		}
		snake[pos].x-=dx[r];snake[pos].y-=dy[r];
	}
	if(check(snake,pos))
		make_snake(snake,pos+1,cost);
}
Beispiel #6
0
	void onepath(TreeNode *root, int sum, queue<int> father) {
		if(root==NULL)	/* because child may be empty, it can be empty */
			return;
		/* judge if reach the leaf */
		if(root->right==NULL&&root->left==NULL){
			if(root->val==sum){
				vector<int> findit;
				while(!father.empty()){
					int value = father.front();
					findit.push_back(value);
					father.pop();
				}
				findit.push_back(sum);
				vec_result.push_back(findit);
			}
			return;
		}
		father.push(root->val);
		sum-=root->val;
		onepath(root->left,sum,father);
		onepath(root->right,sum,father);
	}
Beispiel #7
0
int main(int argc, const char * argv[]) {
    int i,j,m,n,k;
    
    //读入
    sqr sq;
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            scanf("%d",&s[i][j]);
            sq.a[i][j]=s[i][j];
        }
    }
    sq.deep = 0;
    q.push(sq);
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            scanf("%d",&t[i][j]);
        }
    }
    
    printf("%d\n",bfs());
    return 0;
}
int dist(int t, int si, int sj, int ti, int tj) {
	if (si==ti && sj==tj) {
		return 0;
	}
	if (D[t][si][sj][ti][tj] != -1) {
		return D[t][si][sj][ti][tj];
	}

	Q = queue< pair<int, int> >();
	memset(done, 0, sizeof done);
	done[t][si][sj] = 1;
	int ret = -1;
	int sz = 0;
	Si = si;
	Sj = sj;
	Q.push(make_pair(si, sj));

	while (!Q.empty()) {
		if (sz == 0) {
			sz = Q.size();
			++ret;
		}
		--sz;
		int i = Q.front().first;
		int j = Q.front().second;
		Q.pop();
		if (D[t][si][sj][i][j]==-1 || ret<D[t][si][sj][i][j]) {
			D[t][si][sj][i][j] = ret;
		} 

		if (i==ti && j==tj) {
			return ret;
		}

		expand(i, j, t);
	}

	return -1;
}
Beispiel #9
0
void BFS1()
{
    int i, a, b, x, y;
    while(qu1.size())
    {
        a = qu1.front();
        qu1.pop();
        b = qu1.front();
        qu1.pop();
        for(i=0; i<4; i++)
        {
            x = a+xx[i];
            y = b+yy[i];
            if(x<0 or y<0 or x==r or y==c or level[0][x][y]!= 1000006 or mat[x][y]=='#' or mat[x][y]=='F') continue;
            level[0][x][y] = level[0][a][b] + 1;
            qu1.push(x);
            qu1.push(y);

        }

    }
}
void make_map_temp (int x , int y , int type) {
    for (int i = 0 ; i < 3 ; i++) {
        for (int j = 0 ; j < 3 ; j++) {
            map_temp[i][j] = map_cur[i][j];
        }
    }

    switch (type) {
        case 1:
            swap (&map_temp[x][y] , &map_temp[x-1][y]);
            /*for (int i = 0 ; i < 3 ; i++) {
                for (int j = 0 ; j < 3 ; j++) {
                    map_temp[i][j] = map_cur[i][j];
                }
            }*/
            break;
        case 2:
            swap (&map_temp[x][y] , &map_temp[x+1][y]);
            break;
        case 3:
            swap (&map_temp[x][y] , &map_temp[x][y-1]);
            break;
        case 4:
            swap (&map_temp[x][y] , &map_temp[x][y+1]);
            break;
        default:
            return;
    }
    int value = 0;

    for (int i = 0 ; i < 3 ; i++) {
        for (int j = 0 ; j < 3 ; j++) {
            value = value*10 + map_temp[i][j];
        }
    }
    st_que.push (value);
    int dis_temp = dis_map[st_que.front()];
    dis_map.insert (pair<int,int>(value,dis_temp+1));
}
Beispiel #11
0
Datei: d.cpp Projekt: mrain/acm
int main() {
	while (scanf("%d%d", &m, &n) == 2 && (n || m)) {
		memset(d, 0x1F, sizeof(d));
		memset(inq, 0, sizeof(inq));
		while (!q.empty()) q.pop();
		for (int i = 0; i < n; ++ i)
			for (int j = 0; j < m; ++ j) {
				scanf("%s", buf);
				if (!isdigit(buf[0])) g[i][j] = -1;
				else g[i][j] = buf[0] - '0';
				if (buf[0] == 'T') g[i][j] = 0;
				if (buf[0] == 'S') {
					q.push(record(i, j, 0));
					q.push(record(i, j, 1));
					d[i][j][0] = d[i][j][1] = 0;
					inq[i][j][0] = inq[i][j][1] = 1;
				}
			}
		printf("%d\n", bfs());
	}
	return 0;
}
Beispiel #12
0
int main(){
    freopen("in.txt","r",stdin);
    int kase;
    scanf("%d",&kase);
    queue<tt> empty;
    while (kase--){

        scanf("%d %d",&row,&col);
        q=empty;
        for (int i=0;i<row;++i){
            scanf("%s",mp[i]);
            for (int j=0;j<col;++j){
                fire[i][j]=INF;
                if ( mp[i][j]=='F' ){
                    tmp.r=i;
                    tmp.c=j;
                    tmp.val=0;
                    fire[i][j]=0;
                    q.push(tmp);
                }else if ( mp[i][j]=='J' ){
                    joe.r=i;
                    joe.c=j;
                    joe.val=0;
                }
            }
        }
        BFSfire();


        int rr=BFSjoe();
        if ( rr== -1 ){
            printf("IMPOSSIBLE\n");
        }else{
            printf("%d\n",rr);
        }
    }
    return 0;

}
void
Java_cc_openframeworks_OFAndroid_onTouchMoved(JNIEnv*  env, jclass  thiz, jint id,jfloat x,jfloat y,jfloat pressure){
	ofTouchEventArgs touch;
	touch.id = id;
	touch.x = x;
	touch.y = y;
	touch.pressure = pressure;
	touch.type = ofTouchEventArgs::move;
	if(threadedTouchEvents){
		ofNotifyMouseMoved(x,y);
		ofNotifyMouseDragged(x,y,0);
		ofNotifyEvent(ofEvents().touchMoved,touch);
	}else{
		mutex.lock();
		if(accumulateTouchEvents && !touchEventArgsQueue.empty() && touchEventArgsQueue.back().type==ofTouchEventArgs::move){
			touchEventArgsQueue.back() = touch;
		}else{
			touchEventArgsQueue.push(touch);
		}
		mutex.unlock();
	}
}
Beispiel #14
0
   void add_customer( int serv_time )
   {

      //sets timer to 0 for first input, since i reset it on pop its
      //needed for first entry.
      if( time_limit.empty() )
      {  
         timer = 0;
      }

      //puts the serv_time on the queue of time_limits
      time_limit.push( serv_time );

      //add customer to line
      in_line++;

      if( in_line == 6 )
      {
         status = 'i';
      }
 
   }
Beispiel #15
0
main()
{
    int n,k ; scanf("%d%d",&n,&k) ;
    while(k--){int x ; scanf("%d",&x) ; q1.push(x) ;}
    scanf("%d",&k) ;
    while(k--){int x ; scanf("%d",&x) ; q2.push(x) ;}
    for(int cnt=0;cnt<100000000;cnt++)
    {
        if(q1.empty()){printf("%d 2\n",cnt) ; return 0 ;}
        if(q2.empty()){printf("%d 1\n",cnt) ; return 0 ;}
        int x=q1.front() ; q1.pop() ;
        int y=q2.front() ; q2.pop() ;
        if(x>y) q1.push(y) , q1.push(x) ;
        else q2.push(x) , q2.push(y) ;
    }
    printf("-1\n") ;
}
Beispiel #16
0
Datei: d.cpp Projekt: mrain/acm
int main() {
	while (scanf("%d%d", &m, &n) == 2 && n + m) {
		for (int i = 0; i < n; ++ i)
			for (int j = 0; j < m; ++ j)
				scanf("%d", &a[i][j]);
		scanf("%d%d%d%d", &s, &r, &b, &l);
		memset(d, 0x3F, sizeof(d));
		memset(inq, 0, sizeof(inq));
		d[0][0][0] = 0; inq[0][0][0] = true;
		while (!q.empty()) q.pop();
		q.push(make_pair(make_pair(0, 0), 0));
		while (!q.empty()) {
			int x = q.front().first.first, y = q.front().first.second;
			int dir = q.front().second; q.pop();
			int v = d[x][y][dir];
			if (x == n && y == m) continue;
			int nx, ny, ndir;
			//straight;
			ndir = dir; nx = x + dx[ndir]; ny = y + dy[ndir];
			if (valid(nx, ny)) update(nx, ny, ndir, v + (a[x][y] == 0 ? 0 : s));
			//right;
			ndir = (dir + 1) % 4; nx = x + dx[ndir]; ny = y + dy[ndir];
			if (valid(nx, ny)) update(nx, ny, ndir, v + (a[x][y] == 1 ? 0 : r));
			//back;
			ndir = (dir + 2) % 4; nx = x + dx[ndir]; ny = y + dy[ndir];
			if (valid(nx, ny)) update(nx, ny, ndir, v + (a[x][y] == 2 ? 0 : b));
			//left;
			ndir = (dir + 3) % 4; nx = x + dx[ndir]; ny = y + dy[ndir];
			if (valid(nx, ny)) update(nx, ny, ndir, v + (a[x][y] == 3 ? 0 : l));
			inq[x][y][dir] = false;
		}
		int ans = 0x3F3F3F3F;
		for (int k = 0; k < 3; ++ k)
			ans = min(ans, d[n - 1][m - 1][k]);
		cout << ans << endl;
	}
	return 0;
}
Beispiel #17
0
void CSolver::set_var_value(int vid, int value)
{
    assert (value == 0 || value == 1);
    ++ num_implications;

    CVariable & var = variables[vid];
    var.value = value;

    vector<unsigned> & pos_clauses = var.cl_idx [1 - value];
    for (unsigned i=0; i< pos_clauses.size(); ++i) {
	CClause & cl = clauses[pos_clauses[i]];
	++ cl.num_1;
    }

    vector<unsigned> & neg_clauses = var.cl_idx[value];
    for (unsigned i=0; i< neg_clauses.size(); ++i) {
	int cl_id = neg_clauses[i];
	CClause & cl = clauses[cl_id];
	++ cl.num_0;
	if (cl.num_0 == cl.literals.size())
	    conflicts.push_back(neg_clauses[i]);
	else if (cl.num_0 == cl.literals.size() - 1 &&
		 cl.num_1 == 0) {
	    unsigned j;
	    for (j=0; j< cl.literals.size(); ++j) {
		CLiteral lit = cl.literals[j];
		if (variables[VID(lit)].value == UNKNOWN) {
		    CImplication imp;
		    imp.lit = lit;
		    imp.antecedent = cl_id;
		    implication_queue.push(imp);
		    break;
		}
	    }
	    assert (j < cl.literals.size());
	}
    }
}
Beispiel #18
0
int main(){
    int group_num=1,MIN=1000;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
		for (int j = 0; j < n; j++) {
			scanf("%d", &a[i][j]);
			ans[i][j] = -1;
		}
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            if(a[i][j]==1 && group[i][j]==0){
                grouping(i,j,group_num++);
                }
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			if (a[i][j] == 1)
			{
				ans[i][j] = 1;
				q.push(make_pair(i, j));
			}
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            if(a[i][j]==1)
                bfs(i,j);

    for(int i=0; i<n; i++)
        for(int j=0; j<n ; j++)
            for(int k=0; k<2; k++){
                int nx = i+dx[k];
                int ny = j+dy[k];
                if(group[nx][ny] != group[i][j] && nx>=0 && nx<n && ny>=0 && ny<n)
                    MIN=min(MIN,ans[i][j]+ans[nx][ny]);
            }
    printf("%d\n",MIN-2);
                
                
                
}
int main(){
	memset(po,0,sizeof po);
	memset(isp,0,sizeof isp);
	int n;
	scanf("%d",&n);
	for(int x=0;x<n;x++){
		scanf("%s",ploca[x]);
		for(int y=0;y<n;y++)
			if(ploca[x][y]=='*')
				q.push(make_pair(x,y));
	}
	int a,b;
	while(!q.empty()){
		a=q.front().first,b=q.front().second;
		for(int y=0;y<8;y++){
			po[a+sx[y]][b+sy[y]]++;
		}
		q.pop();
	}
	bool tako=0;
	for(int x=0;x<n;x++){
		scanf("%s",red);
		for(int y=0;y<n;y++)
			if(red[y]=='x'){
				if(ploca[x][y]=='*')
					tako=1;
				isp[x][y]='0'+po[x][y];
			}else 
				isp[x][y]='.';
	}
	if(tako)
		for(int x=0;x<n;x++)
			for(int y=0;y<n;y++)
				if(ploca[x][y]=='*')
					isp[x][y]='*';
	for(int x=0;x<n;x++)
		printf("%s\n",isp[x]);
}
Beispiel #20
0
int bfs(){
    int i,j,k;
    
    while(!q.empty()){
        sqr sq=q.front();
        q.pop();
        
        //判断是否到达目标
        bool flag = false;
        for(i=0;i<3;i++){
            for(j=0;j<3;j++){
                if(sq.a[i][j]!=t[i][j]){
                    flag = true;
                }
            }
        }
        if(!flag)return sq.deep;
        
        //移动
        for(i=0;i<3;i++){
            for(j=0;j<3;j++){
                if(sq.a[i][j]==0){
                    for(k=0;k<4;k++){
                        int x1=i,y1=j,x2=i+d[k][0],y2=j+d[k][1];
                        if(!check(x2,y2))continue;
                        swap(sq.a[x1][y1],sq.a[x2][y2]);
                        sq.deep++;
                        q.push(sq);
                        swap(sq.a[x1][y1],sq.a[x2][y2]);
                        sq.deep--;
                    }
                }
            }
        }
    }
    
    return INF;
}
Beispiel #21
0
int bfs() {
    int code = encode(0, SRC);
    q.push({code, 0});
    vis[code] = true;
    while (!q.empty()) {
        Item item = q.front();
        q.pop();
        code = item.c;
        int d = item.d;
        int pos, x;
        decode(code, pos, x);
        if (x == DST) return d;
    
        swap0(pos, x, d);
        swap1(pos, x, d);
        up(pos, x, d);
        down(pos, x, d);
        left(pos, x, d);
        right(pos, x, d);
    }
    assert(0);
    return 0;
}
int main(){
	scanf("%d %d", &comida, &acciones);
	for(int i=1; i<=acciones; i++){
		scanf(" %c", &accion);
		switch(accion){
			case 'N':
				scanf("%d", &peques);
				canguros.push(peques);
				break;
			case 'A':
				comida-= canguros.front() + 1;
				canguros.pop();
				break;
			case 'C':
				printf("%d\n", canguros.size());
				break;
			case 'R':
				printf("%d\n", comida);
				break;
		}
	}
	return 0;
}
void find_augmenting_path() {
    init_bfs();
    while (!Q.empty()) {
        int u = Q.front(); Q.pop();
        FOR (v, 1, n)
            if (a[u][v] && match[u] != v && b[u] != b[v]) {
                if ((v == start || match[v]) &&  T[match[v]])
                    blossom_shrink(u, v);
                else if (!T[v]) {
                    if (!match[v]) {
                        T[v] = u;
                        finish = v;
                        return;
                    }
                    else {
                        T[v] = u;
                        Q.push(match[v]);
                        in_queue[match[v]] = true;
                    }
                }
            }
    }
}
Beispiel #24
0
void timer(int i)
{
	static bool init;
	if (!init)
		last_ticks = GetTickCount();
	init = true;

	long long new_ticks = GetTickCount();
	while (frames.size() > 0 && new_ticks - frames.front() > 1000)
		frames.pop();

	char *buf = new char[5];
	sprintf(buf, "%d", frames.size());
	prepare_text(window[0], window[1], 0, 0, buf, vec4(1.0, 1.0, 1.0, 1.0), aspect, 12);

	frames.push(new_ticks);
	last_ticks = new_ticks;

	scene_tact();
	render_all();
	update_pos();
	glutTimerFunc(timer_ticks, timer, 0);
}
int bfs()
{
	int x_var,y_var,x,y;
	int temp_x[]={-2,-2,-1,-1, 1, 1, 2, 2};
	int temp_y[]={-1, 1, 2,-2, 2,-2, 1,-1};
	while(!q.empty())
	{
		node curr=q.front();
		x_var=curr.x_pos;
		y_var=curr.y_pos;
		q.pop();
		for(int i=0;i<8;i++)
		{
			x=temp_x[i]+x_var;
			y=temp_y[i]+y_var;
			if(x <0 || y <0 || x >9 || y >9 || matrix[x][y]==false)
			continue;
			matrix[x][y]=false;
			//cout<<"x="<<x<<"y="<<y<<"\n";
			q.push(node(x,y));
		}
	}
}
Beispiel #26
0
void bfs()
{
	while(!q.empty())
	{
		ND now=q.front();q.pop();
		//cout<<now.sta<<' '<<now.x0<<' '<<now.y0<<endl;
		for(int k=0;k<4;k++)
		{
			ND tmp;
			if(!expand(now,tmp,k)) continue;
			if(tmp.sta==tar)
			{
				printf("%d\n",tmp.step);
				exit(0);
			}
			if(!h[tmp.sta])
			{
				h[tmp.sta]=1;
				q.push(tmp);
			}
		}
	}
}
void expendNode(node &tmp)
{
    unordered_set<string> :: iterator it;
    node here;
    here.len = tmp.len + 1;
    int len1 = from.size();
    for (int i = 0;i < len1;i++)
    {
        int index = -1;
        while ((index = tmp.now.find(from[i],index + 1)) != string::npos)
        {
            string build = tmp.now.substr(0,index) + to[i] + tmp.now.substr(index + from[i].size());
            it = dict.find(build);
            if (it == dict.end())
            {
                dict.insert(build);
                here.now = build; // ÅÐÖزÅÈë¶Ó
                myque.push(here);
            }

        }
    }
}
void NetWorkThreadProc::sendData(RequestMessage* msg)
{
	// 还没有连接到网络
	if (g_NetworkStat == NetworkStat_NotConnect)
	{
		CCLog("Error : %s:%d---> g_NetworkStat == NetworkStat_NotConnect .throw packet.",__FUNCTION__,__LINE__);
		// 通知还没连接到网络
		GlobalNetworkMsgDispacher::getMsgDispacher()->addPakage(new GlobalNetPackage(Type_Send_Err,NULL,NULL));
		delete msg;
		return;
	}
	MessageAutoLock lock;
	//// 有数据还没处理
	//if (requestMsgQueue.size() > 0)
	//{
	//	CCAssert(false,"为了以后方便,就不要一次发多个请求");
	//	// 通知发送错误
	//	GlobalNetworkMsgDispacher::getMsgDispacher()->addPakage(new GlobalNetPackage(Type_Send_Err,NULL,NULL));
	//	delete msg;
	//	return;
	//}
	requestMsgQueue.push(msg);
}
Beispiel #29
0
int bfs()
{
	while(q.size()){
		ss=q.front();
		q.pop();vis[ss.v]=1;
		NODE *p=gra[ss.v].next;
		while(p!=NULL){
			tt.v=p->v;
			tt.num=ss.num^1;
			if(vis[tt.v]){
				p=p->next;
				continue;
			}
			if(co[tt.v]==ss.num)return 1;
			co[tt.v]=tt.num;
			q.push(tt);
			if(!vis2[tt.v])fans[tt.num].push(tt.v),fanum[tt.num]++;
			vis2[tt.v]=1;
			p=p->next;
		}
    }
    return 0;
}
Beispiel #30
0
int main()
{
    int n,m,k,i,x,y,z;
    in >> n >> m >> k;
    for(i=1;i<=n;++i)
        best[i] = 1 << 29;
    for(i = 1 ; i <= k ; ++ i)
    {
        in >> x;
        best[x] = 0;
        root[x] = x;
        q.push(x);
    }
    for(i = 1 ; i <= m ; ++ i)
    {
        in >> x >> y >> z;
        graf[x].push_back((edge){y,z});
        graf[y].push_back((edge){x,z});
    }
    b_ford();
    afis(n);
    return 0;
}