/* Write a search for WA. After the game found direct violence not super Ah,,, *//************************************************* Author:P owatr* Created time:2015-8-30 14:55: 10* File name:b.cpp ************************************************/#include <cstdio> #include <algorithm& GT, #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include < string> #include <vector> #include <queue> #include <deque> #include <stack> #include < list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime >using namespace std; #define Lson L, Mid, RT << 1#define Rson mid + 1, R, RT << 1 | 1typedef long ll;const int MAXN = 4e3 + 10;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;int a[maxn][maxn];vecto r<int> G[maxn];int Main () {int n, m; while (~SCANF ("%d%d", &n, &m)) {int x, y; memset (A, 0, sizeof (a)); for (int i = 1; I <= n; i++) g[i].Clear (); for (int i = 1; I <= m; i++) {scanf ("%d%d", &x, &y); A[x][y] = a[y][x] = 1; G[x].push_back (y); G[y].push_back (x); } int min1 = INF; for (int i = 1, i <= N; i++) {for (int j = i + 1; j <= N; j + +) {if (A[i][j]) { for (int k = j + 1; k <= N; k++) {if (A[i][k] && a[k][j]) {int temp = G[i].size () + g[j].size () + g[k].size (); min1 = min (min1,temp); }}}}} if (min1 = = INF) puts ("-1"); else printf ("%d\n", min1-6); } return 0;}
Codeforces Round #318 [Russiancodecup Thanks-round] (Div. 2)--b Pure violence--bear and Three Musketeers