diffusion
Title Description
A point every time unit diffuses a distance in the four directions, as shown in FIG.
Tulio
Two points a, b communication, referred to as E (a, b), if and only if the diffusion regions a, b are common. Definition of communication block is arbitrary two points within the block u, v path will exist without fail e (u, a0), e (a0, a1), ..., e (ak, v). Given input format of
the first line of a number n, the n lines, each line point coordinates.
Input Format
[Data] scale
For 20% of the data, to meet 1≤N≤5; 1≤X [i], Y [i] ≤50;
To 100% of the data satisfies 1≤N≤50; 1≤X [i], Y [i] ≤10 ^ 9.
Output Format
A number representing the earliest time point of all the communication block is formed.
N input sample to the point on the output plane, and asked what is the earliest time that they form a communication block.
Must first know the minimum time into two communicating Harman Dayton two blocks is the distance, which is the most critical;
longest side is required then the n points of minimum spanning tree;
Code:
#include<bits/stdc++.h>
#define LL long long
#define pa pair<int,int>
#define ls k<<1
#define rs k<<1|1
#define inf 0x3f3f3f3f
using namespace std;
const int N=100100;
const int M=2000100;
const int mod=1e9;
int head[N],cnt,n,x[100],y[100],fa[100];
struct Node{
int fa,sn,w;
}edge[N*2];
void add(int p,int q,int w){
edge[cnt].fa=p;
edge[cnt].sn=q;
edge[cnt].w=w;
cnt++;
}
bool cmp(Node p,Node q){return p.w<q.w;}
int find(int p){
if(p==fa[p]) return p;
return fa[p]=find(fa[p]);
}
int krus(){
sort(edge,edge+cnt,cmp);
int tot=0,ans=0;
for(int i=0;i<cnt;i++){
if(find(edge[i].fa)!=find(edge[i].sn)){
tot++;
fa[find(edge[i].sn)]=find(edge[i].fa);
ans=max(edge[i].w,ans);
}
if(tot==n-1) break;
}
return ans;
}
int main(){
memset(head,-1,sizeof(head));
cin>>n;
for(int i=1;i<=n;i++) fa[i]=i;
for(int i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
int d=abs(x[j]-x[i])+abs(y[j]-y[i]);
d=(d+1)/2;
add(i,j,d),add(j,i,d);
}
}
cout<<krus()<<endl;
return 0;
}