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. int x, y;
  31. int dfs(int u, int c) {
  32. color[u] = c;
  33. if (color[u] == 0) x++;
  34. if (color[u] == 1) y++;
  35. for (auto v : adj[u]) {
  36. if (color[v] == -1)
  37. dfs(v, c^1);
  38. }
  39. return (x>0 && y > 0 && x != y);
  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. for (int i = 0; i < v.size(); i++) {
  52. for (int j = 0; j < v.size(); j++) {
  53. if (i == j)continue;
  54. ll dx = v[i][0]-v[j][0], dy = v[i][1]-v[j][1];
  55. ll dist = dx*dx + dy*dy;
  56. ll r = v[i][2]+v[j][2];
  57. if (r*r == dist) {
  58. adj[i].push_back(j);
  59. adj[j].push_back(i);
  60. }
  61. }
  62. }
  63.  
  64. fin(0, n) {
  65. if (color[i] == -1) {
  66. if (dfs(i, 0) > 0) {
  67. x = 0, y = 0;
  68. return void(cout << "YES\n");
  69. }
  70. }
  71. }
  72.  
  73. cout << "NO\n";
  74. }
  75.  
  76. int main() {
  77. FAST;
  78. #ifndef ONLINE_JUDGE
  79. freopen("input.txt", "r", stdin);
  80. freopen("output.txt", "w", stdout);
  81. #endif
  82. int tt = 1; //cin >> tt;
  83. while (tt--) {
  84. solve();
  85. //cout << "Case #" << c++ << ": ";
  86. }
  87. return 0;
  88. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
NO