MasssA


私信TA

用户名:1294309339

访问量:34857

签 名:

城市学院的渣渣

等  级
排  名 104
经  验 7930
参赛次数 6
文章发表 73
年  龄 0
在职情况 学生
学  校 城市学院的渣渣
专  业

  自我简介:

城市学院的渣渣

解题思路:

注意事项:

参考代码:

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=310;
const int inf=0x3f3f3f;
int n,m,tot=1,ans=inf,c[maxn],sum[maxn],son[maxn][maxn];
bool flag[maxn];
vector<int> v[maxn];
void build(int i)
{
    flag[i]=1;
    for(int j=0;j<v[i].size();j++)
    {
        int tmp=v[i][j];
        if(!flag[tmp])
        {
            son[i][++sum[i]]=tmp;
            build(tmp);
        }
    }
}
void search(int p)
{
    int get=0;
    if(ans<=tot) return;
    for(int i=1;i<=n;i++)
    if(c[i]==p)
    for(int j=1;j<=sum[i];j++)
    {
        get=1;
        tot++;
        c[son[i][j]]=p+1;
    }
    tot--;
    for(int i=1;i<=n;i++)
    if(c[i]==p+1)
    {
        c[i]=0;
        search(p+1);
        c[i]=p+1;
    }
    tot++;
    for(int i=1;i<=n;i++)
    if(c[i]==p+1)
    {
        c[i]=0;
        tot--;
    }
    if(get==0)
    {
        ans=min(ans,tot);
        return;
    }
}
int main()
{
    int x,y;
    cin>>n>>m;c[1]=1;
    for(int i=1;i<=m;i++)
    {
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    build(1);
    search(1);
    cout<<ans;
    return 0;
}

 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区