fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. #define ii pair<int, int>
  6. #define fi first
  7. #define se second
  8. const int maxn = 3e6 + 25;
  9. const int mod = 1e9 + 7;
  10. const int oo = 1e16 + 7;
  11.  
  12. #define all(x) x.begin(), x.end()
  13.  
  14. int dx[] = {0, 1, -1, 0};
  15. int dy[] = {1, 0, 0, -1};
  16.  
  17. int n, m;
  18. bitset<2003> adj[1005];
  19.  
  20.  
  21. void solve()
  22. {
  23. cin >> n >> m;
  24. for(int i = 1; i <= m; i++)
  25. {
  26. int u, v; cin>> u >> v;
  27. adj[u].set(v, 1);
  28.  
  29. adj[v].set(u, 1);
  30. }
  31. for(int i = 1; i <= n; i++)
  32. {
  33. for(int j = 1; j <= n; j++)
  34. {
  35. if(i == j) continue;
  36. if((adj[i] & adj[j]).count() < 3) continue;
  37. for(int k = 1; k <= n; k++)
  38. {
  39. if(k == j || k == i) continue;
  40.  
  41. if((adj[i] & adj[j] & adj[k]).count() >= 3)
  42. {
  43. cout << "YES\n";
  44. return ;
  45. }
  46. }
  47. }
  48. }
  49. cout << "NO\n";
  50. }
  51.  
  52.  
  53. int32_t main()
  54. {
  55. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  56. if(fopen("main.inp", "r"))
  57. {
  58. freopen("main.inp", "r", stdin);
  59. // freopen("main.out", "w", stdout);
  60. }
  61. int test = 1;
  62. // cin >> test;
  63. while(test--) solve();
  64. }
  65.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
NO