Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ii pair<int, int>
- #define X first
- #define Y second
- int n, m, k;
- vector<int> G[2000];
- int cor[2000], tempo = 1;
- bool check(ii c1, ii c2, int r1, int r2) {
- return (c1.X - c2.X) * (c1.X - c2.X) + (c1.Y - c2.Y) * (c1.Y - c2.Y) <= (r1 + r2) * (r1 + r2);
- }
- vector<int> border(ii c, int r) {
- int x = c.X, y = c.Y;
- vector<int> b;
- if(x - r <= 0) b.push_back(k);
- if(x + r >= n) b.push_back(k + 1);
- if(y + r >= m) b.push_back(k + 2);
- if(y - r <= 0) b.push_back(k + 3);
- return b;
- }
- void dfs(int v) {
- cor[v] = tempo;
- for(int &w : G[v])
- if(cor[w] < tempo)
- dfs(w);
- }
- int32_t main() {
- vector<ii> centers;
- vector<int> raios;
- scanf(" %d %d %d", &n, &m, &k);
- for(int i = 0; i < k; i++) {
- int x, y, r;
- scanf(" %d %d %d", &x, &y, &r);
- centers.push_back({x, y});
- raios.push_back(r);
- }
- for(int i = 0; i < k; i++) {
- for(int j = i + 1; j < k; j++)
- if(check(centers[i], centers[j], raios[i], raios[j])) {
- G[i].push_back(j);
- G[j].push_back(i);
- }
- vector<int> b = border(centers[i], raios[i]);
- for(int &w : b) {
- G[w].push_back(i);
- G[i].push_back(w);
- }
- }
- bool fl = true;
- tempo++;
- dfs(k);
- if(cor[k + 1] == tempo)
- fl = false;
- tempo++;
- dfs(k + 1);
- if(cor[k + 2] == tempo or cor[k] == tempo)
- fl = false;
- tempo++;
- dfs(k + 2);
- if(cor[k + 1] == tempo or cor[k + 3] == tempo)
- fl = false;
- tempo++;
- dfs(k + 3);
- if(cor[k + 2] == tempo or cor[k] == tempo)
- fl = false;
- puts(fl ? "S" : "N");
- return 0;
- }
Add Comment
Please, Sign In to add comment