Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- int main()
- {
- // freopen("i.txt","r",stdin);
- // freopen("o.txt","w",stdout);
- int n,m;
- cin>>n>>m;
- bool adj[n+3][n+3];
- int deg[n+3];
- for(int i=1;i<=n+1;i++)
- deg[i]=0;
- for(int i=1;i<=n+1;++i)
- {
- for(int j=1;j<=n+2;++j)
- adj[i][j]=false;
- }
- while(m--)
- {
- int a,b;
- cin>>a>>b;
- adj[a][b]=true;
- adj[b][a]=true;
- deg[a]++;
- deg[b]++;
- }
- int result=100005;
- for(int i=1;i<=n;++i)
- {
- for(int j=i+1;j<=n;++j)
- {
- if(adj[i][j])
- {
- for(int k=j+1;k<=n;++k)
- {
- if(adj[k][i] && adj[k][j])
- result= min(result,(deg[i]+deg[j]+deg[k]));
- //cout<<result<<endl;
- //cout<<i<<" "<<j<<" "<<k<<endl;}
- }
- }
- }
- }
- if(result==100005)
- cout<<"-1"<<"\n";
- else
- cout<<result-6<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement