문제

링크

풀이

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
 
bool solve(void) {
  int n; cin >> n;
  vector<int> x(n), y(n);
  for (int i=0; i<n; i++) cin >> x[i] >> y[i];
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
 
  for (int i=1; i<n; i++) {
    if (x[i] == x[i-1] || y[i] == y[i-1]) return false;
  }
  return true;
}
 
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
 
  int t; cin >> t;
  while (t--) cout << (solve() ? "SAFE" : "NOT SAFE") << "\n";
  return 0;
}