This is the basic question of the minimum tree structure. I will not go into details about the meaning of the question. When I think about this question, I find it very difficult.
Because I often use input optimization when I input them, I usually directly input the optimization for these inputs, but after I had T 20 times, I found that the reason for input optimization was T. After I changed it to scanf, I dropped.
For example, change the comment of the following code to input optimization.
I don't know. Please answer.
# Include <set> # include <map> # include <stack> # include <cmath> # include <queue> # include <cstdio> # include <string> # include <vector> # include <iomanip> # include <cstring> # include <iostream> # include <algorithm> # define Max 2505 # define FI first # define SE second # define ll long # define PI acos (-1, 1.0) # define inf 0x7fffffff # define LL (x) (x <1) # define bug puts ("here") # define PII pair <in T, int> # define RR (x) (x <1 | 1) # define mp (a, B) make_pair (a, B) # define mem (a, B) memset (a, B, sizeof (a) # define REP (I, s, t) for (int I = (s); I <= (t ); ++ I) using namespace std; inline void RD (int & ret) {char c; int flag = 1; do {c = getchar (); if (c = '-') flag =-1;} while (c <'0' | c> '9'); ret = c-'0 '; while (c = getchar ()> = '0' & c <= '9') ret = ret * 10 + (c-'0'); ret * = Flag;} inline void OT (int a) {if (a> = 10) OT (a/10); putchar (a % 10 + '0 ');} inline void RD (double & ret) {char c; int flag = 1; do {c = getchar (); if (c = '-') flag =-1 ;} while (c <'0' | c> '9'); ll n1 = c-'0'; while (c = getchar ()> = '0' & c <= '9') {n1 = n1 * 10 + c-'0';} ll n2 = 1; while (c = getchar ()> = '0' & c <= '9') {n1 = n1 * 10 + c-'0 '; n2 * = 10;} re T = flag * (double) n1/(double) (n2 );} /*************************************** * *****/# define N 1005 struct PP {double x, y;} p [N]; struct kdq {int s, e; double l;} ed [N * N]; int n, m; double getdis (int I, int j) {return sqrt (p [I]. x-p [j]. x) * (p [I]. x-p [j]. x) + (p [I]. y-p [j]. y) * (p [I]. y-p [j]. y);} int pre [N], vis [N], id [N]; double in [N]; double Directed_MST (int root, int V, int E) {double ret = 0; while (1) {for (int I = 1; I <V; I ++) in [I] = inf; for (int I = 0; I <E; I ++) {int s = ed [I]. s; int e = ed [I]. e; if (in [e]> ed [I]. l & s! = E) {pre [e] = s; in [e] = ed [I]. l ;}} for (int I = 1; I <V; I ++) {if (I = root) continue; if (in [I] = inf) return-1;} int cntnode = 1; mem (vis,-1); mem (id,-1); in [root] = 0; for (int I = 1; I <V; I ++) {ret + = in [I]; int v = I; while (vis [v]! = I & id [v] =-1 & v! = Root) {vis [v] = I; v = pre [v];} if (v! = Root & id [v] =-1) {for (int u = pre [v]; u! = V; u = pre [u]) {id [u] = cntnode;} id [v] = cntnode ++ ;}} if (cntnode = 1) break; for (int I = 1; I <V; I ++) {if (id [I] =-1) id [I] = cntnode ++ ;} for (int I = 0; I <E; I ++) {int s = ed [I]. s; int e = ed [I]. e; ed [I]. s = id [s]; ed [I]. e = id [e]; if (id [s]! = Id [e]) ed [I]. l-= in [e];} V = cntnode; root = id [root];} return ret;} int main () {while (scanf ("% d", & n, & m )! = EOF) {for (int I = 1; I <= n; I ++) {scanf ("% lf", & p [I]. x, & p [I]. y) ;}for (int I = 0; I <m; I ++) {// RD (ed [I]. s); RD (ed [I]. s); scanf ("% d", & ed [I]. s, & ed [I]. e); if (ed [I]. s! = Ed [I]. e) // remove self-ring ed [I]. l = getdis (ed [I]. s, ed [I]. e); else ed [I]. l = inf;} double ans = Directed_MST (1, n + 1, m); if (ans =-1) printf ("poor snoopy \ n "); else printf ("%. 2f \ n ", ans);} return 0 ;}