302944: CF574B. Bear and Three Musketeers

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Bear and Three Musketeers

题意翻译

给你一张n点m边的无向图,要求你找出三个点,要求: 1. 它们组成了一个环 2. **除了其他两个点**,每个点的邻居个数总和要求最少 如果你能找出这三个点,输出这3个点的邻居(**除了其他两个点**)之和 如果你一个点也没找着,输出-1 (3<=n<=4000,0<=m<=4000) (1<=ai,bi<=n)

题目描述

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.

输入输出格式

输入格式


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.

输出格式


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 $ 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.

Input

题意翻译

给你一张n点m边的无向图,要求你找出三个点,要求: 1. 它们组成了一个环 2. **除了其他两个点**,每个点的邻居个数总和要求最少 如果你能找出这三个点,输出这3个点的邻居(**除了其他两个点**)之和 如果你一个点也没找着,输出-1 (3<=n<=4000,0<=m<=4000) (1<=ai,bi<=n)

加入题单

算法标签: