C. Anadi and Domino 《 Codeforces Round #588 (Div. 2) 》
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ppb pop_back #define mp make_pair #define masout for(int i = 0; i < n; i++ ) cout << a[i];return 0; bool c[10][10]; int main () { int n, m; cin >> n >> m; for(int i = 0; i < m; i++ ) {int u,v;cin>>u>>v;c[u][v]=[v][u]=1;} if(n <= 6) cout << m, exit(0); int mn = 1e9; for(int i = 1; i <= 7; i++ )
for(int j = 1; j <= 7; j++)
{
int x = 0;
for(int k = 1; k <= 7; k++ )
if(c[i][k] && c[k][j]) x++;
mn = min(mn , x);
} cout << m - mn; }
#include<bits/stdc++.h> using namespace std; typedef long long int LL; #define sc(x) scanf("%d",&x) #define scc(x,y) scanf("%d%d",&x,&y) #define sccc(x,y,z) scanf("%d%d%d",&x,&y,&z) #define mkp(a,b) make_pair(a,b) #define F first #define pb(a) push_back(a) #define S second #define pii pair<int,int> #define mem0(a) memset(a,0,sizeof(a)) #define mem(a,b) memset(a,b,sizeof(a)) #define MID(l,r) (l+((r-l)>>1)) #define ll(o) (o<<1) #define rr(o) (o<<1|1) const LL INF = 0x3f3f3f3f ; const int maxn = 10000; const double pi = acos(-1.0); int T,n,m; bool vis[10][10]; bool used[10][10]; int num[10]; int ans=0; void dfs(int dep) { if(dep==0) { mem0(used); int tmp=0; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(i==j)continue; if(vis[i][j]==0)continue; if(used[num[i]][num[j]]==0) { tmp++; used[num[i]][num[j]]=1; used[num[j]][num[i]]=1; } } } ans=max(ans,tmp); return ; } for(int i=1;i<=6;i++) { num[dep]=i; dfs(dep-1); } } int main() { while(cin>>n>>m) { mem0(vis); int l,r; while(m--) { cin>>l>>r; vis[l][r]=vis[r][l]=1; } ans=0; dfs(n); cout<<ans<<endl; } return 0; }
所遇皆星河