求助,各位大佬看看孩子吧
查看原帖
求助,各位大佬看看孩子吧
955141
tndbsfk楼主2023/6/5 13:14
#include <iostream>
#include<vector>
#include<cstring>
using namespace std;
int n,m,i,s,e,ans=0,count=0;
const int M=1005;
vector<int> G[M];
bool used[M]= {0};
int time1[M],node[M];

void dfs(int q,int mark)
{
    if(q==e)
    {
        ans++;
        for(i=0; i<mark; i++)
        {
            time1[node[i]]++;
        }
        return;
    }
    if(mark>=G[q].size())
        return;
    for(i=0; i<G[q].size(); i++)
    {
        int a=G[q][i];
        if(!used[a])
        {
            used[a]=true;
            node[mark]=a;
            dfs(a,mark+1);
            node[mark]=0;
            used[a]=false;

        }
    }
}
int main()
{
    memset(time1,0,sizeof(time1));
    memset(node,0,sizeof(node));
    int u,v;
    cin>>n>>m;
    for(i=0; i<m; i++)
    {
        cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    cin>>s>>e;
    used[s]=true;
    dfs(s,0);
    if(ans==0)
        cout<<"-1";
    else
    {
        for(i=1; i<=n; i++)
        {
            if(time1[i]==ans)
            {
                count++;
            }
        }
         cout<<count-1<<endl;
    }
    return 0;
}

2023/6/5 13:14
加载中...