Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- using pii = pair<ll, ll>;
- using p3i = pair<pii, ll>;
- int n, sx, sy, tx, ty;
- vector<p3i> cs;
- vector<int> fa;
- void init(int n) { fa = vector<int>(n, -1); }
- int find(int x)
- {
- if (fa[x] == -1)
- return x;
- return fa[x] = find(fa[x]);
- }
- int join(int x, int y)
- {
- int px = find(x);
- int py = find(y);
- if (px == py) {
- return px;
- }
- return fa[py] = px;
- }
- long double epsilon = 1e-7;
- long double dist(ll x1, ll y1, ll x2, ll y2)
- {
- long double dx = (long double) (x1) -x2;
- long double dy = (long double) (y1) -y2;
- return sqrt(dx * dx + dy * dy);
- }
- ll dist_sq(ll x1, ll y1, ll x2, ll y2)
- {
- ll dx = x1 - x2;
- ll dy = y1 - y2;
- return dx * dx + dy * dy;
- }
- bool pts_on_cirle(ll x, ll y, const p3i &c)
- {
- // return abs(dist(x, y, c.first.first, c.first.second) - c.second) <= epsilon;
- return dist_sq(x, y, c.first.first, c.first.second) == c.second * c.second;
- }
- bool circles_sect(const p3i &c1, const p3i &c2)
- {
- ll x1 = c1.first.first, y1 = c1.first.second, x2 = c2.first.first, y2 = c2.first.second;
- /*
- long double r1 = c1.second, r2 = c2.second;
- if (dist(x1, y1, x2, y2) > r1 + r2 + epsilon) {
- return false;
- }
- if (dist(x1, y1, x2, y2) + epsilon < abs(r1 - r2)) {
- return false;
- }
- return true;
- */
- ll r1 = c1.second, r2 = c2.second;
- if (dist_sq(x1, y1, x2, y2) > (r1 + r2) * (r1 + r2)) {
- return false;
- }
- if (dist_sq(x1, y1, x2, y2) < (r1 - r2) * (r1 - r2)) {
- return false;
- }
- return true;
- }
- int main(int argc, char **argv)
- {
- scanf("%d", &n);
- cs = vector<p3i>(n + 1);
- scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
- ll x, y, r;
- for (int i = 0; i < n; ++i) {
- scanf("%lld%lld%lld", &x, &y, &r);
- cs[i] = {{x, y}, r};
- }
- init(n);
- int fs = -1, ft = -1;
- for (int i = 0; i < n; ++i) {
- if (pts_on_cirle(sx, sy, cs[i]))
- fs = i;
- if (pts_on_cirle(tx, ty, cs[i]))
- ft = i;
- for (int j = i + 1; j < n; ++j) {
- if (circles_sect(cs[i], cs[j])) {
- join(i, j);
- }
- }
- }
- if (fs == -1 || ft == -1) {
- printf("No\n");
- } else {
- printf("%s\n", (find(fs) == find(ft) ? "Yes" : "No"));
- }
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement