Thanks to some unknown Dalao blog, I just know how to solve the problem ....
At first, even the test instructions were read wrong .... The story tells us to read the question well.
Description Description
Figure G is an undirected connected graph with no self-loops and at most one edge between two points. We define the vertex v,u shortest path is the path from V to u that passes the least edge. All vertices that are contained in the shortest path of the v-u are called v-u geodetic vertices, and the set of these vertices is recorded as I (V, u).
We call set I (V, u) as a geodetic set.
For example, I (2, 5) ={2, 3, 4, 5},i (1, 5) ={1, 3, 5},i (2, 4) ={2, 4}.
Given a graph G and a number of points to v,u, ask you to find I (V, u) separately.
Input format
The first row of two integer n,m, respectively, represents the number of vertices and the number of sides of the graph G (vertex number 1-n)
Next to M lines, two integers per line A, a, a, A and B indicates that there is an no-forward edge between vertices a and B.
Line M+2 has an integer k representing the given point logarithm.
Next to K lines, two integers per line v,u.
Output format
A total of k lines, each line corresponding to each point in the input file to V,u, the vertex number in ascending order of the output I (V, u). Each number in the same row is separated by a space.
Sample input to sample
5 6
0 S
1 3
2 3
2 4
3 5
4 5
3
2 5
5 1
2 4
Sample output Sample Outputs
2 3 4 5
1 3 5
2 4
The idea is quite simple, floyed the shortest path again
And then loop judgment and record the points within the set, but the implementation looks like a ghost animal!? Thanks for the small amount of data .....
#include <bits/stdc++.h>
#define MAXN 100
using namespace Std;
struct node{
int x, y;
}A[10086];
int n,m,kk;
int FU[MAXN][MAXN],S[MAXN][MAXN];
int DIS[MAXN][MAXN][MAXN];
int main () {
cin>>n>>m;
memset (fu,10,sizeof (FU));
for (int i=1;i<=n;i++)
fu[i][i]=0;
for (int i=1;i<=m;i++) {
int xx,yy;
cin>>xx>>yy;
Fu[xx][yy]=1;fu[yy][xx]=1;
}
cin>>kk;
for (int i=1;i<=kk;i++) {
cin>>a[i].x>>a[i].y;
}
for (int k=1;k<=n;k++)
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
if (Fu[i][k]+fu[k][j]<fu[i][j])//floyed to find the shortest circuit
FU[I][J]=FU[I][K]+FU[K][J];
for (int k=1;k<=n;k++)
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
if (Fu[i][k]+fu[k][j]==fu[i][j])//Because the slack has been done, the description is the shortest path if the condition is determined
Dis[i][j][++s[i][j]]=k;//i,j fixed position, array S[i][j] record number of points, dis array storage vertex
for (int i=1;i<=kk;i++) {
for (int j=1;j<=s[a[i].x][a[i].y];j++)//enumeration of the number of points within the collection
cout<<dis[a[i].x][a[i].y][j]<< ";
cout<<endl;
}
return 0;
}
Geodetic Collection C + +