Test instructions is to give a diagram that is not connected, and then define a diameter: the distance between two points of the shortest distance in the Unicom component.
To connect the two connected components in an disconnected graph, the new component can be generated with a minimum diameter, and the new diameter is output.
The idea is to use Floyd to find the shortest distance between any two points, and then find the distance from each point to the farthest point of the component at which the point is before the new diagram is generated. Then enumerate the two unconnected two points, the maximum distance between the components of the two points, plus the distance between the two points, is the diameter of the newly generated pasture.
The title guarantee will have the two components of the non-unicom:
However: the 7th Test point of the problem I was dead or alive, and then the data analysis of the discovery, this test point in all the points are connected.
I have also specifically demonstrated before that the diameter of a component inside must be less than the diameter of the newly generated component after two components are connected. The results of this test data and topic description inconsistent with the pit I don't want to say anything.
I just want to ask about the basic trust between people.
/*id:modengd1prog:cowtourlang:c++*/#include <iostream> #include <stdio.h> #include <memory.h># Include <math.h> #define INF 0xfffffffusing namespace Std;typedef pair<int,int> coor;double longestdist[151 ];d ouble a[151][151]; Coor coor[151];bool con[151][151];int n;void Floyd () {//Seek the shortest path between two points of arbitrary indirection and mark the indirect link between them for (int k=0;k<n;k++) {for (int. i=0;i<n;i++) {if (a[i][k]!=inf&&k!=i) for (int j=0;j<n;j++) {if (a[k][j]!=inf&&k!=j) {a[i][j]=min (a[i][j],a[i][k]+a[ K][J]); Con[i][j]=true; }}}}}double dis (Coor a,coor B) {return sqrt ((a.first-b.first) * (A.first-b.first) + (a.second-b.sec Ond) * (A.second-b.second));} void Slove () {double ans=inf; Find the distance in the component where each node is farthest from this node for (int i=0;i<n;i++) {for (int j=0;j<n;j++) {if (con[i][ J]) { Longestdist[i]=max (Longestdist[i],a[i][j]); }}}//enumerates any two disconnected points and simulates connecting these two points to form a new pasture diameter for (int i=0;i<n-1;i++) {for (int j=1+i;j<n;j++) {if (!con[i][j]) {ans=min (Ans,longestdist[i]+longestdist[j]+dis (coor[i],coor[j ])); }}} for (int i=0;i<n;i++)//processing if the data has been fully connected to what to do (the topic stressed that there must be no connection between the two points, and meet this test data and the topic description is not the same I was drunk Ans=max (longest Dist[i],ans); printf ("%.6lf\n", ans);} int main () {freopen ("cowtour.in", "R", stdin); Freopen ("Cowtour.out", "w", stdout); scanf ("%d", &n); int A, B; Char ch; for (int i=0;i<n;i++) {scanf ("%d%d", &a,&b); Coor[i].first=a; Coor[i].second=b; } getchar (); for (int i=0;i<n;i++) {for (int j=0;j<n;j++) {scanf ("%c", &ch); if (ch== ' 0 ')//determine whether to connect directly and initialize the A array to Floyd {Con[i][j]=false; A[i][j]=inf; } else {con[i][j]=true; A[i][j]=dis (Coor[i],coor[j]); }} getchar (); con[i][i]=true;//oneself to oneself must be unicom and distance is 0 a[i][i]=0; } Floyd (); Slove (); return 0;}
Usaco Cow Tours