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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是用C语言改写的代码: ```c #include <stdio.h> int week(int m, int d, int year){ // 判断输入日期是否合法 if (m < 1 || m > 12 || d < 1 || d > 31){ return -1; } if ((m == 4 || m == 6 || m == 9 || m == 11) && d > 30){ return -1; } if (m == 2){ if ((d > 29) || (d == 29 && (year % 4 != 0 || (year % 100 == 0 && year % 400 != 0)))){ return -1; } } // 计算该日期是该年的第几天 int days_in_month[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; int day_of_year = days_in_month[m-1] + d; if (m > 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)){ day_of_year += 1; } // 计算该日期是该年的第几周 int first_day = (2 - (year % 4)) % 7 + 1; // 确定该年1月1日是星期几 int first_week_days; if (first_day == 1){ first_week_days = 1; } else{ first_week_days = 8 - first_day; } int week_of_year = (day_of_year - first_week_days) / 7 + 1; return week_of_year; } int main(){ int dates[5][2] = {{1, 1}, {1, 5}, {13, 1}, {2, 29}, {4, 31}}; int year = 2022; for (int i = 0; i < 5; i++){ int m = dates[i][0]; int d = dates[i][1]; printf("The week of %d/%d in %d is %d\n", m, d, year, week(m, d, year)); } return 0; } ``` 首先,在C语言中,没有Python中的列表和字符串格式化输出,需要使用数组和printf函数来实现。其次,需要注意Python中的整数除法//在C语言中是/,需要进行修改。最后,需要在调用函数时传入年份参数。 运行结果与Python代码一样,不再赘述。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值