CF574B.Bear and Three Musketeers

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Do you know a story about the three musketeers? Anyway, you will learn about its origins now.

Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.

There are nn warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers.

Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions.

输入格式

The first line contains two space-separated integers, nn and mm ( 3<=n<=40003<=n<=4000 , 0<=m<=40000<=m<=4000 ) — respectively number of warriors and number of pairs of warriors knowing each other.

ii -th of the following mm lines contains two space-separated integers aia_{i} and bib_{i} ( 1<=ai,bi<=n1<=a_{i},b_{i}<=n , aibia_{i}≠b_{i} ). Warriors aia_{i} and bib_{i} know each other. Each pair of warriors will be listed at most once.

输出格式

If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes).

输入输出样例

  • 输入#1

    5 6
    1 2
    1 3
    2 3
    2 4
    3 4
    4 5
    

    输出#1

    2
    
  • 输入#2

    7 4
    2 1
    3 6
    5 1
    1 7
    

    输出#2

    -1
    

说明/提示

In the first sample Richelimakieu should choose a triple 11 , 22 , 33 . The first musketeer doesn't know anyone except other two musketeers so his recognition is 00 . The second musketeer has recognition 11 because he knows warrior number 44 . The third musketeer also has recognition 11 because he knows warrior 44 . Sum of recognitions is 0+1+1=20+1+1=2 .

The other possible triple is 2,3,42,3,4 but it has greater sum of recognitions, equal to 1+1+1=31+1+1=3 .

In the second sample there is no triple of warriors knowing each other.

首页