Advertisement
JouJoy

X

Dec 12th, 2021
757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5.  
  6.  
  7. int main()
  8.  
  9. {
  10.     // freopen("i.txt","r",stdin);
  11.    // freopen("o.txt","w",stdout);
  12.    
  13.     int n,m;
  14.     cin>>n>>m;
  15.     bool adj[n+3][n+3];
  16.     int deg[n+3];
  17.     for(int i=1;i<=n+1;i++)
  18.         deg[i]=0;
  19.     for(int i=1;i<=n+1;++i)
  20.         {
  21.             for(int j=1;j<=n+2;++j)
  22.                 adj[i][j]=false;
  23.         }
  24.  
  25.  
  26.     while(m--)
  27.     {
  28.         int a,b;
  29.         cin>>a>>b;
  30.         adj[a][b]=true;
  31.         adj[b][a]=true;
  32.         deg[a]++;
  33.         deg[b]++;
  34.     }
  35.  
  36.     int result=100005;
  37.         for(int i=1;i<=n;++i)
  38.         {
  39.             for(int j=i+1;j<=n;++j)
  40.             {
  41.                 if(adj[i][j])
  42.                 {
  43.                     for(int k=j+1;k<=n;++k)
  44.                     {
  45.                         if(adj[k][i] && adj[k][j])
  46.                             result= min(result,(deg[i]+deg[j]+deg[k]));
  47.                             //cout<<result<<endl;
  48.                              //cout<<i<<" "<<j<<" "<<k<<endl;}
  49.                     }
  50.                 }
  51.             }
  52.  
  53.         }
  54.         if(result==100005)
  55.             cout<<"-1"<<"\n";
  56.         else
  57.             cout<<result-6<<"\n";
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement