n rings and a rope with a length of 1 m
Ask the right hand to hold any 2 rings up to a few ropes straightened
Hold which 2 don't know so 22 enum
For 2 rings You can consider the shortest possible short circuit and then there may be a number of the shortest lines in the path statistics.
I know how to get out of a sample.
Example 3 is a ring pull 0 and 2 you have 2 of the shortest, each one is 3.
Example 4 is the same
#include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std;
const int MAX = 130;
int A[max][max];
int Map[max][max];
BOOL Vis[max][max];
int n,m;
int cnt;
void Floyd () {int i,j,k; for (k = 0, k < n; k++) for (i = 0, i < n; i++) for (j = 0; J < N; j + +) A[i][j] = min (a[i][j],a[i][k]+a[k][
J]);
} void BFs (int s,int e) {queue <int> q;
Q.push (s);
int i;
while (!q.empty ()) {int u = q.front ();
Q.pop ();
for (i = 0; i < n; i++) {if (vis[u][i]) continue;
if (!map[u][i]) continue;
if (A[e][i] + 1 = = A[e][u]) {cnt++;
Vis[u][i] = Vis[i][u] = true;
Q.push (i);
}}}} int main () {int t,cas = 1;
int i,j;
int s,e;
scanf ("%d", &t);
while (t--) {memset (a,0,sizeof (a));
memset (map,0,sizeof (map));
scanf ("%d%d", &n,&m);
for (i = 0; i < n; i++) for (j = 0; J < N; j + +) {if (i = = j) A[i][j] = 0;
else a[i][j] = 999999999; } for (i = 0; i < m; i++) {scanf ("%d%d", &s,&e);
A[s][e] = A[e][s] = 1;
Map[s][e] = Map[e][s] = 1;
} Floyd ();
int max = 0;
for (i = 0, i < n; i++) {for (j = i+1; J < N; j + +) {if (a[i][j] = = 999999999) continue;
memset (vis,false,sizeof (VIS));
CNT = 0;
BFS (I,J);
if (Max < CNT) max = CNT;
}}//printf ("%d%d\n", a[0][1],a[1][0]);
printf ("Case #%d:%d\n", Cas++,max);
} return 0; }