-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneps520.cpp
More file actions
56 lines (44 loc) · 1.01 KB
/
Copy pathneps520.cpp
File metadata and controls
56 lines (44 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Contest : Neps
* Problem : 520 - Tarzan
* Link : https://neps.academy/br/exercise/520
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
vector<vector<int>> adj;
vector<bool> visited;
void dfs(int no) {
visited[no] = true;
for (auto &v : adj[no])
if (!visited[v]) dfs(v);
}
using ll = long long;
int main() {
fastio
int n, d;
cin >> n >> d;
adj.assign(n, vector<int>());
visited.assign(n, false);
vector<pair<int, int>> v(n);
for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
// dist entre dois pontos
if (sqrt(pow(v[i].first - v[j].first, 2) + pow(v[i].second - v[j].second, 2)) <= d) {
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
int cnt = 0;
for (int i = 0; i < n; i++) {
if (!visited[i]) {
dfs(i);
cnt++;
}
}
cout << (cnt == 1 ? 'S' : 'N') << '\n';
return 0;
}