标签:
/* 写搜索WA了。。赛后发现直接暴力不会超啊,,, */ /************************************************ * Author :Powatr * Created Time :2015-8-30 14:55:10 * File Name :B.cpp ************************************************/ #include <cstdio> #include <algorithm> #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 | 1 typedef long long ll; const int MAXN = 4e3 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int a[MAXN][MAXN]; vector<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纯暴力——Bear and Three Musketeers
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4770907.html