Skip to content

Instantly share code, notes, and snippets.

@enzerr
Created January 15, 2023 23:36
Show Gist options
  • Save enzerr/f8e388ae52a88c163af02c4d0d0e6010 to your computer and use it in GitHub Desktop.
Save enzerr/f8e388ae52a88c163af02c4d0d0e6010 to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
int x[maxn], y[maxn], mark[maxn];
vector<int> adj[maxn];
int dist(int i, int j){
return abs(x[i]-x[j]) + abs(y[i]-y[j]);
}
void dfs(int u){
mark[u] = true;
for(int v : adj[u])
if(!mark[v]) dfs(v);
}
int main(){
int X, Y; cin >> X >> Y;
int n, A; cin >> n >> A;
A/=100;
for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i!=j && dist(i, j)<=A)
adj[i].push_back(j);
}
}
int comp = 0;
for(int i = 0; i < n; i++) if(!mark[i]){
comp++;
dfs(i);
}
cout << comp-1 << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment