n个人参加某项特殊考试。
为了公平,要求任何两个认识的人不能分在同一个考场。
求是少需要分几个考场才能满足条件。
输入格式:
第一行,一个整数n(1<n<100),表示参加考试的人数。
第二行,一个整数m,表示接下来有m行数据
以下m行每行的格式为:两个整数a,b,用空格分开 (1<=a,b<=n) 表示第a个人与第b个人认识。
输出格式:
一行一个整数,表示最少分几个考场。
例如:
输入:
5
8
1 2
1 3
1 4
2 3
2 4
2 5
3 4
4 5
程序应该输出:
4
再比如:
输入:
5
10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
则程序应该输出:
5
资源约定:
峰值内存消耗 < 256M
CPU消耗 < 1000ms
请严格按要求输出,不要画蛇添足地打印类似:“请您输入…” 的多余内容。
所有代码放在同一个源文件中,调试通过后,拷贝提交该源码。
注意:不要使用package语句。不要使用jdk1.7及以上版本的特性。
public class Main {
public static void main(String[] args) {
Scanner love=new Scanner(System.in);
Map<Integer,List> m=new HashMap();
List l;
int n=love.nextInt();
int z=love.nextInt();
for(int i=0;i<z;i++){
int k=love.nextInt();
int v=love.nextInt();
if(m.get(k)==null){
l=new ArrayList();
}else {
l=m.get(k);
}
l.add(v);
m.put(k,l);
}
int count=0;
boolean flag=false;
for(int i=1;i<n+1;i++){
if(i==1) {
count=1;
continue;
}
int sum=0;
for(int j=i-1;j>0;j--){
List list = m.get(j);
Iterator iterator = list.iterator();
while (iterator.hasNext()){
flag=false;
if(i==(int)iterator.next()){
flag=true;
break;
}
}
if (flag){
sum++;
}
}
if (sum==i-1){
count++;
}
}
System.out.println(count);
}
}