CF574B.Bear and Three Musketeers
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
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 n 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.
你听说过三个火枪手的故事吗?无论如何,你现在将了解它的起源。
里谢利马基厄是熊城的一位红衣主教。他厌倦了独自应对犯罪活动,需要三位勇敢的战士来协助他打击坏人。
共有 n 名战士。里谢利马基厄想从中选出三人成为火枪手,但这并不容易。最重要的条件是:这三位火枪手必须彼此相识,以便高效协作;同时他们又不能太过知名,否则可能被老朋友出卖。对每位火枪手而言,其“知名度”定义为:他所认识的战士人数(不包括另外两位火枪手)。
请帮助里谢利马基厄!判断是否存在三名彼此相识的战士可被选为火枪手;若存在,求他们知名度之和的最小可能值。
输入格式
The first line contains two space-separated integers, n and m (3 ≤ n ≤ 4000, 0 ≤ m ≤ 4000) — respectively number of warriors and number of pairs of warriors knowing each other.
i-th of the following m lines contains two space-separated integers a__i and b__i (1 ≤ a__i, b__i ≤ n, a__i ≠ b__i). Warriors a__i and b__i know each other. Each pair of warriors will be listed at most once.
第一行包含两个用空格分隔的整数 n 和 m(3≤n≤4000,0≤m≤4000),分别表示战士的数量以及相互认识的战士对的数量。
接下来的 m 行中,第 i 行包含两个用空格分隔的整数 ai 和 bi(1≤ai,bi≤n,ai=bi)。战士 ai 和 bi 相互认识。每对战士至多被列出一次。
输出格式
If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes).
如果里谢利马克耶夫能选出三名火枪手,请输出他们知名度之和的最小可能值;否则,输出 -1(不带引号)。
输入输出样例
输入#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 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recognitions is 0 + 1 + 1 = 2.
The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3.
In the second sample there is no triple of warriors knowing each other.
在第一个样例中,Richelimakieu 应选择三元组 1,2,3。第一位火枪手除其余两位火枪手外不认识任何人,因此他的知名度为 0;第二位火枪手的知名度为 1,因为他认识战士 4;第三位火枪手的知名度也为 1,因为他也认识战士 4。知名度总和为 0+1+1=2。
另一可能的三元组是 2,3,4,但其知名度总和更大,为 1+1+1=3。
在第二个样例中,不存在彼此相互认识的三位战士组成的三元组。
输入解题思路,AI测评打分。不知道怎么写?