Skip to content

Commit

Permalink
20240604 Eunoiay's submission for CF1949I (Yawn-Sean#3188)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunoiay authored Jun 4, 2024
1 parent 921ed29 commit 62b269e
Showing 1 changed file with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);

int n;
cin >> n;

vector<int> x(n), y(n), r(n);
for (int i = 0; i < n; ++i) {
cin >> x[i] >> y[i] >> r[i];
}

vector<vector<int>> adj(n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < i; ++j) {
i64 dx = x[i] - x[j];
i64 dy = y[i] - y[j];
i64 dis = r[i] + r[j];
if (dx * dx + dy * dy == dis * dis) {
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}

vector<int> clr(n, -1);
bool flg = false;

for (int i = 0; i < n; ++i) {
if (~clr[i]) {
continue;
}
clr[i] = 0;

stack<int> stk;
int c[2] = {};

c[0] = 1;
stk.push(i);

bool f = true;
while (!stk.empty()) {
auto u = stk.top();
stk.pop();

for (auto v : adj[u]) {
if (clr[v] == -1) {
clr[v] = clr[u] ^ 1;
c[clr[v]] += 1;
stk.push(v);
} else if (clr[u] == clr[v]) {
f = false;
}
}
}
if (f && c[0] != c[1]) {
flg = true;
break;
}
}

cout << (flg ? "YES" : "NO") << "\n";

return 0;
}

0 comments on commit 62b269e

Please sign in to comment.