fork download
  1. #include <bits/stdc++.h>
  2. #define endl '\n'
  3.  
  4. using namespace std;
  5. const int MAXN = (int)5e3 + 42;
  6.  
  7. int n, m;
  8. vector<int> G[MAXN];
  9. int has[MAXN][MAXN];
  10.  
  11. void read()
  12. {
  13. cin >> n >> m;
  14.  
  15. for(int i = 0; i < m; i++)
  16. {
  17. int u, v;
  18. cin >> u >> v;
  19. G[u].push_back(v);
  20. G[v].push_back(u);
  21. }
  22. }
  23.  
  24. /*
  25. int dist[MAXN];
  26. int par[MAXN];
  27.  
  28. void dfs(int u)
  29. {
  30. int sz = G[u].size(), v;
  31. for(int i = 0; i < sz; i++)
  32. {
  33. v = G[u][i];
  34. if(dist[v] == -1)
  35. {
  36. dist[v] = dist[u] + 1;
  37. par[v] = u;
  38. dfs(v);
  39. }
  40. else if(dist[v] == dist[u] - 3)
  41. {
  42. int ver = u;
  43. cout << "TAIP" << endl;
  44. for(int k = 0; k < 4; k++, ver = par[ver])
  45. cout << ver << " ";
  46. cout << endl;
  47. exit(0);
  48. }
  49. }
  50. }
  51. */
  52.  
  53. void solve()
  54. {
  55. memset(has, -1, sizeof(has));
  56. //dist[1] = 0;
  57. //dfs(1);
  58.  
  59. for(int ver = 1; ver <= n; ver++)
  60. {
  61. for(int j = 0; j < G[ver].size(); j++)
  62. for(int i = j + 1; i < G[ver].size(); i++)
  63. {
  64. int v = G[ver][j], u = G[ver][i];
  65. if(has[v][u] != -1 || has[u][v] != -1)
  66. {
  67. cout << "TAIP" << endl;
  68. cout << u << " " << ver << " " << v << " " << has[u][v] << endl;
  69. return;
  70. }
  71.  
  72. has[u][v] = ver;
  73. has[v][u] = ver;
  74. }
  75. }
  76.  
  77. cout << "NE" << endl;
  78. }
  79.  
  80. int main()
  81. {
  82. ios_base::sync_with_stdio(false);
  83. cin.tie(NULL);
  84.  
  85. read();
  86. solve();
  87. return 0;
  88. }
  89.  
  90.  
Success #stdin #stdout 0.11s 102784KB
stdin
Standard input is empty
stdout
NE