fork download
  1. /*
  2. * Author: Geeza
  3.  */
  4.  
  5. #include <bits/stdc++.h>
  6.  
  7. #define ld long double
  8. #define ll long long
  9. #define pb push_back
  10. #define fin(a, n) for(int i = a; i < n; i++)
  11. #define fjn(a, n) for(int j = a; j < n; j++)
  12. #define all(a) a.begin(),a.end()
  13. #define allr(a) a.rbegin(),a.rend()
  14. #define FAST ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
  15.  
  16. using namespace std;
  17.  
  18. const double PI = acos(-1);
  19. const int N = 2e3+10;
  20. const ll oo = 0x3f3f3f3f3f3f3f3f;
  21. const int MOD = 1000000007, inf = 1e18;
  22.  
  23. string di[] = {"D","L", "U", "R", "UL", "UR", "DL", "DR"};
  24. // int dx[] = {+1, +0, +0, -1, -1, -1, +1, +1};
  25. // int dy[] = {+0, -1, +1, +0, -1, +1, -1, +1};
  26. char dc[] = {'D', 'L', 'R', 'U'};
  27.  
  28. vector<vector<int>> adj;
  29. vector<int> color;
  30. bool bad;
  31.  
  32. void dfs(int u, int c) {
  33. if (bad) return;
  34. color[u] = c;
  35. for (auto v : adj[u]) {
  36. if (color[v] == -1)
  37. dfs(v, c^1);
  38. if (color[v] == c) bad = true;
  39. }
  40. }
  41.  
  42. void solve() {
  43. int n; cin >> n;
  44. vector<array<ll, 3>> v;
  45. fin(0, n) {
  46. ll x, y, r; cin >> x >> y >> r;
  47. v.push_back({x, y, r});
  48. }
  49. adj = vector<vector<int>>(n+1);
  50. color.assign(n+1, -1);
  51. bad = false;
  52. for (int i = 0; i < v.size(); i++) {
  53. for (int j = 0; j < v.size(); j++) {
  54. if (i == j)continue;
  55. ll dx = v[i][0]-v[j][0], dy = v[i][1]-v[j][1];
  56. ll dist = dx*dx + dy*dy;
  57. ll r = v[i][2]+v[j][2];
  58. if (r*r == dist) {
  59. adj[i].push_back(j);
  60. adj[j].push_back(i);
  61. }
  62. }
  63. }
  64.  
  65. fin(0, n) {
  66. if (color[i] == -1) {
  67. dfs(i, 0);
  68. }
  69. }
  70.  
  71. if (bad) return void(cout << "NO\n");
  72. cout << "YES\n";
  73. }
  74.  
  75. int main() {
  76. FAST;
  77. #ifndef ONLINE_JUDGE
  78. freopen("input.txt", "r", stdin);
  79. freopen("output.txt", "w", stdout);
  80. #endif
  81. int tt = 1; //cin >> tt;
  82. while (tt--) {
  83. solve();
  84. //cout << "Case #" << c++ << ": ";
  85. }
  86. return 0;
  87. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
YES