C++ 程序实现dfs时出现不可预测的错误

C++ 程序实现dfs时出现不可预测的错误,c++,graph,depth-first-search,C++,Graph,Depth First Search,事实上,我的代码是针对codechef()上的FIRESC问题编写的,当我在代码块上编译它时,它工作得很好,但当我在站点上提交它时,它会显示错误(错误答案)。plz帮助我发现很难找到错误。。 这是我的代码() #包括 #定义MAXSIZE 10000 #定义pb推回 使用namespace::std; int-dfs(向量>b; g[a].pb(b); g[b].pb(a); } firesc(g,N,result); COut声明“BoOL vs[n+1”)不符合C++标准,因为(n+1)不是

事实上,我的代码是针对codechef()上的FIRESC问题编写的,当我在代码块上编译它时,它工作得很好,但当我在站点上提交它时,它会显示错误(错误答案)。plz帮助我发现很难找到错误。。 这是我的代码()

#包括
#定义MAXSIZE 10000
#定义pb推回
使用namespace::std;
int-dfs(向量&g,int-v,bool-vs[])
{
vs[v]=真;
整数计数=1;
for(auto-it=g[v].begin();it!=g[v].end();++it)//auto-it:g[v])
如果(!vs[*it])
计数+=dfs(g,*it,vs);
返回计数;
}
void firesc(向量和g、整数n、向量和结果)
{
布尔vs[n+1];
vs[0]=真;
对于(int i=1;i M;
向量g(N+1);
而(M--)
{
//couta>>b;
g[a].pb(b);
g[b].pb(a);
}
firesc(g,N,result);

COut声明“BoOL vs[n+1”)不符合C++标准,因为(n+1)不是常数。这是一个编译器特定的扩展。但是我已经把n’传递给函数FiReSc,所以它不是函数的范围内的常量吗?任何建议来纠正这个问题…
#include<bits/stdc++.h>

#define MAXSIZE 10000
#define pb push_back
using namespace::std;

int dfs(vector< vector < int> > &g, int v, bool vs[])
{
    vs[v] = true;
    int count = 1;
    for(auto it = g[v].begin() ; it != g[v].end() ; ++it)//auto it : g[v])
        if(!vs[*it])
        count += dfs(g,*it,vs);
    return count;
}

void firesc(vector <vector <int> > &g, int n, vector <int> &result)
{
    bool vs[n+1];
    vs[0] = true;
    for(int i =1 ; i <= n ; ++i)
        vs[i] = false;
    for(int i = 0 ; i <= n ; ++i)
    if(!vs[i])
        result.pb(dfs(g,i,vs));
}
int main()
{                                                                         //0     1   2   3   4
    int T,N,M,a,b,ways = 1;                                                 //    2   1   2
    vector <int> result;                                                      //      3

    //cout<<"\nenter T :\t";
    cin>>T;
    while(T--)
    {
      //  cout<<"\nenter N and M :\t";
        cin>>N>>M;
        vector <vector <int> > g(N+1);
        while(M--)
        {
        //    cout<<"\nenter couples of friends :\t";
            cin>>a>>b;
            g[a].pb(b);
            g[b].pb(a);
        }
        firesc(g,N,result);
    cout<<result.size()<<' ';                                                                                  //cout<<"\n total routes :\t "<<result.size();
    for(auto it = result.begin() ; it != result.end() ; ++it )          //int x : result
        ways *= (*it);

         cout<<ways%((1000000000+7))<<endl;                                                               //cout<<"\ntotal ways to select captains "<<ways;

    result.clear();
                                                                                /************************* for(auto it : g)
                                                                                                            g[(*it)].clear();*******/

    g.clear();
    ways = 1;
    }

    return 0;
}