创建std :: vector对象C ++时出错

时间:2013-01-23 10:21:28

标签: c++ graph stl vector

我一直在使用STL一段时间,但今天我遇到了这个错误:

error: no class template named 'rebind' in 'class std::vector<int, std::allocator> >'

在以下程序中:

#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bitset>
#include <climits>
#include <stack>
#include <cctype>
#include <sstream>
using namespace std;

vector<int, vector<int> > G[2000005];
vector<int, vector<int> > Grev[2000005];
int f[2000005], order[2000005], leader[2000005], t = 0, parent = 0;
bool explored[2000005];

void dfs_reverse(int i) {
    explored[i] = true;
    for(vi::iterator it=G[i].begin(); it != G[i].end(); it++)
        if(!explored[*it])
            dfs_reverse(*it);
    t++;
    f[i] = t;
}

void dfs(int i) {
    explored[i] = true;
    leader[i] = parent;
    for(vi::iterator it=G[i].begin(); it != G[i].end(); it++)
        if(!explored[*it])
            dfs(*it);
}

int main()  {
    int N, i, j, u, v;

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    scanf("%d", &N);
    for(i=0; i<N; i++)  {
        scanf("%d %d", &u, &v);
        if(u > 0)   {
            if(v > 0)   {
                G[N + u].push_back(v); G[N + v].push_back(u);
                Grev[v].push_back(N + u); Grev[u].push_back(N + v);
            } else  {
                G[N + u].push_back(N - v); G[-v].push_back(u);
                Grev[N-v].push_back(N+u); Grev[u].push_back(-v);
            }
        } else  {
            if(v > 0)   {
                G[-u].push_back(v); G[N + v].push_back(N - u);
                Grev[v].push_back(-u); Grev[N-u].push_back(N+v);
            } else  {
                G[u].push_back(N - v); G[-v].push_back(N - u);
                Grev[N-v].push_back(u); Grev[N-u].push_back(-v);
            }
        }
    }

    memset(explored, false, 2000005*sizeof(bool));
    for(i=2*N; i>0; i--)    {
        if(!explored[i])
            dfs_reverse(i);
        order[f[i]] = i;
    }

    memset(explored, false, 2000005*sizeof(bool));
    for(i=2*N; i>0; i--)    {
        if(!explored[order[i]]) {
            parent = order[i];
            dfs(order[i]);
        }
    }

    for(i=1; i<=N; i++)
        if(leader[i] == leader[N+i])
            break;

    if(i <= N)
        printf("Unsatisfiable\n");
    else    printf("Satisfiable\n");

    return 0;
}

我正在尝试使用Kosaraju的两遍算法来解决2SAT问题,以找到强连通分量。基本上,我要为大图(2000000个节点)分配内存。我用矢量&gt;这样做G [2000005]但它给了我上面提到的错误。如何解决此错误?

1 个答案:

答案 0 :(得分:5)

问题是vector<int, vector<int>。第二个模板参数, vector<int>没有意义。您可能打算std::vector<std::pair<int, vector<int> >std::map<int, std::vector<int>