F - First Day

 IME Starters Try-outs 2018

F - First Day

Statements

IME students are going to their first military field training. They will be placed in certain areas, individually, but a student in a certain area may be able to see other areas, so, in order to avoid distractions, no student should be able to see any other.

Earlier, for field reconnaissance, soldiers were placed in all areas. During that, two IMPORTANT things were noticed:

  • The sum of the number soldiers that each soldier could see is 2×n−2, where n is the number of soldiers;
  • If an officer says to any soldier to raise his hand and to all others to only raise theirs if they see another soldier with their hand already raised, eventually all soldiers will have raised their hand.

IME instructors are asking you to help them to find out how many students at most can be placed at the same time. To do so, they will give you which areas can be seen from each area.

Input

The first line contains two integers, nn and mm (1≤n≤1051≤n≤105, 0≤m≤min(105,n×(n−1)/2)) — the number of areas and the number of relations.

The next mm lines contains the relations between the areas. Each line has two integers, aiai and ajaj (1≤ai,aj≤n), meaning that students in the areas aiai and ajaj can see each other.

Output

Output the number of students that can do the activity at the same time without seeing others.

Example

Input

5 4
1 2
1 3
2 4
2 5

Output

3

DFS

当前选1下一个必为0。

当前选0则为0或1中大的。

#include <bits/stdc++.h>
using namespace std;
const int maxn=100005;
int n,m,dp[maxn][2];
vector <int> p[maxn];
void dfs(int now,int pre)
{
    dp[now][0]=0;
    dp[now][1]=1;
    for(int i=0;i<p[now].size();i++)
    {
        if(p[now][i]==pre)  continue;
        dfs(p[now][i],now);
        dp[now][0]+=max(dp[p[now][i]][0],dp[p[now][i]][1]);
        dp[now][1]+=dp[p[now][i]][0];
    }


}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        p[a].push_back(b);
        p[b].push_back(a);
    }
    dfs(1,1);
    int t=max(dp[1][1],dp[1][0]);
    printf("%d\n",t);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/xuanhuangwendao/article/details/81214016