SPEA算法模板

http://blog.csdn.net/u011742541/article/details/12916609

bool SPEA( int s )
{
    queueque;
    memset( outque,0,sizeof(outque) );
    memset( vis,0,sizeof(vis) );
    for( int i = 0; i < n; i ++ )
        dis[i] = inf;
    dis[s] = 0;
    que.push( s );
    vis[s] = true;
    while( !que.empty() )
    {
        int x = que.front(); que.pop();
        vis[x] = false;
        outque[x] ++;
        if( outque[x] > n )
            return false;
        for( int i = 0; i < map[x].size(); i ++ )
        {
            node u = map[x][i];
            if( u.w != inf && dis[u.id] > dis[x] + u.w )
            {
                dis[u.id] = dis[x] + u.w;
                if( !vis[u.id] )
                {
                    vis[u.id] = true;
                    que.push( u.id );
                }
            }
        }
    }
    return true;
}


你可能感兴趣的:(模板锦集)