fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(0);
  6. cin.tie(0);
  7.  
  8. int n, m;
  9. cin >> n >> m;
  10.  
  11. vector<unordered_set<int>> tab(n+1);
  12. for (int i = 0; i < m; i++) {
  13. int a, b;
  14. cin >> a >> b;
  15. tab[a].insert(b);
  16. tab[b].insert(a);
  17. }
  18. int c;
  19. cin >> c;
  20. for(int i=0; i<c; i++) {
  21. int a, b;
  22. cin >> a >> b;
  23. if (tab[a].count(b)) {
  24. cout << "TAK" << endl;
  25. } else {
  26. cout << "NIE" << endl;
  27. }
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 5320KB
stdin
6 5
1 2
5 2
5 1
3 4
4 4
5
4 3
3 4
2 1
5 4
2 1
stdout
TAK
TAK
TAK
NIE
TAK