Topic Link: Click to open the link
Test instructions: from 1 to 2, make the longest path as small as possible.
See the code for details:
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include < string> #include <vector> #include <stack> #include <bitset> #include <cstdlib> #include < cmath> #include <set> #include <list> #include <deque> #include <map> #include <queue># Define MAX (a) > (b)? ( A):(B) #define MIN (a) < (b) ( A):(B)) using namespace Std;typedef long long ll;typedef long double ld;const ld EPS = 1e-9, PI = 3.14159265358979323846264 33832795;const int mod = 1000000000 + 7;const int INF = int (1e9);//& 0x7fffffffconst int seed = 131;const ll INF64 = ll (1e18); const int MAXN = + 10;int t,n,m,cnt,p[maxn],kase=0;double ans[maxn][maxn],x[maxn],y[maxn];struct Node {in t A, B; Double Dist; Node (int a=0, int b=0, double dist=0): A (a), B (b), dist (dist) {} BOOL operator < (const node& RHS) Const { Return Dist < rhs.dist; }}a[maxn*maxn];vector<node> g[maxn];int _find (int x) {REturn P[x] = = x? X:P[X] = _find (p[x]); }void dfs (int u, int fa) {int len = g[u].size (); for (int i=0;i<len;i++) {int v = g[u][i].a; if (v! = FA) {Ans[1][v] = max (Ans[1][u], g[u][i].dist); DFS (v, u); }}}double Solve () {for (int i=1;i<=n;i++) P[i] = i, g[i].clear (); Sort (A, a+cnt); for (int i=0;i<cnt;i++) {int x = _find (A[I].A); int y = _find (a[i].b); if (x! = y) {p[x] = y; G[a[i].a].push_back (node (a[i].b, 0, a[i].dist)); G[a[i].b].push_back (node (a[i].a, 0, a[i].dist)); }} Ans[1][1] =-1.0; DFS (1, 1); return ans[1][2];} int main () {while (~SCANF ("%d", &n) && N) {for (int i=1;i<=n;i++) scanf ("%lf%lf", &x[i],&y[ I]); CNT = 0; for (int i=1;i<=n;i++) {for (int j=i+1;j<=n;j++) {Double cur = sqrt ((X[i]-x[j]) * (X[i]- X[J]) + (Y[i]-y[j]) * (Y[i]-y[j])); A[cnt++] = node (i,j,cur); }} printf ("Scenario #%d\n", ++kase); printf ("Frog Distance =%.3f\n\n", Solve ()); } return 0;}
POJ 2253 Frogger (minimum spanning tree)