AC ~ I have been debugging a question for N years ~~ I still can't do it in English. I read the variable meaning in the question wrong! How can I debug the results ~~ Tragedy ~
Finally, it's over ~~
----------------------------------------------------------------- Split line --------------------------------------------------------------------------------------
The composition of this question is not very difficult. The key is to understand the question. In addition, my card is to use floyd in each region. How can I determine the minimum number of walls that each member has to climb to a certain gathering place ?? Because each member can belong to two regions, if the enumerated member's region is directly added, it is a 2 ^ n complexity algorithm, which is obviously not desirable. So I thought for a moment last night, and it would be enough to enumerate the areas of the party, that is, 255 + areas. In this way, even if each member belongs to two areas, there is a minimum value in the area of the party. The minimum value is the number of walls that the member goes to the party. Add the number of walls to each member. The answer is the minimum value ~~
I read the online solution report, but I cannot understand the code they wrote. The format is ugly ~~ I 'd better think about it myself ~
After comparison, I found that the original question was wrong ~ Tragedy ~~
# Include <iostream> # include <string. h> # define MAXN 255 # define MAXM 222 # define MAXL 35 # define INF 0 xfffffffusing namespace std; int M, N, L; int line [MAXN] [MAXN] [2]; int map [MAXM] [MAXM]; int mber [MAXN]; int list [MAXN]; int getMin (int, int B) {return a <B? A: B;} void prework () {int I, j; memset (line, 0, sizeof (line); scanf ("% d", & N, & L); for (I = 1; I <= L; I ++) scanf ("% d", & mber [I]); for (I = 1; I <= M; I ++) for (j = 1; j <= M; j ++) map [I] [j] = I = j? 0: INF;} void makeMap () {int I, j, k; for (I = 1; I <= M; I ++) {scanf ("% d ", & k); for (j = 0; j <k; j ++) scanf ("% d", & list [j]); int a, B; for (j = 0; j <k; j ++) {a = list [j]; B = list [(j + 1) % k]; if (line [a] [B] [0] = 0) line [a] [B] [0] = line [B] [a] [0] = I; else {map [I] [line [a] [B] [0] = map [line [a] [B] [0] [I] = 1; line [a] [B] [1] = line [B] [a] [1] = I ;}}} void Floyd () {int I, j, k; for (k = 1; k <= M; k ++) for (I = 1; I <= M; I ++) for (j = 1; j <= M; j + +) If (map [I] [j]> map [I] [k] + map [k] [j]) map [I] [j] = map [I] [k] + map [k] [j];} void getAns () {int z, sum; int I, j; int min = INF, index; for (z = 1; z <= M; z ++) // enumeration area {sum = 0; for (I = 1; I <= L; I ++) {int u = mber [I]; index = INF; for (j = 1; j <= N; j ++) {if (line [u] [j] [0]! = 0) {int v1 = line [u] [j] [0]; int v2 = line [u] [j] [1]; index = getMin (index, getMin (map [v1] [z], map [v2] [z]);} sum + = index;} if (min> sum) min = sum ;} printf ("% d \ n", min); return;} int main () {while (scanf ("% d", & M )! = EOF) {prework (); makeMap (); Floyd (); getAns ();} return 0 ;}