fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, m;
  6. cin >> n >> m;
  7. int ms[n][n] = {};
  8. for (int i = 0; i < m; i++) {
  9. int a, b;
  10. cin >> a >> b;
  11. a--; b--;
  12. if (ms[a][b] == 1 || ms[b][a] == 1) {
  13. cout << "YES" << endl;
  14. return 0;
  15. }
  16. ms[a][b] = 1;
  17. ms[b][a] = 1;
  18. }
  19. cout << "NO" << endl;
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 5284KB
stdin
5 3
1 3
2 3
2 5
stdout
NO