比赛 |
test2 |
评测结果 |
AAAAAAAAAA |
题目名称 |
Geodetic 集合 |
最终得分 |
100 |
用户昵称 |
31627012 |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2017-03-12 20:32:59 |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstring>
#define itn int
using namespace std;
const int maxn=45;const int inf=2000;
int n,m,dis[maxn][maxn],k;int temp1,temp2;
inline void readln(){
freopen("geo.in","r",stdin);
freopen("geo.out","w",stdout);
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if (i==j) dis[i][j]=0;
else dis[i][j]=dis[j][i]=inf;
}
}
for (int i=1;i<=m;i++){
scanf("%d%d",&temp1,&temp2);
dis[temp1][temp2]=dis[temp2][temp1]=1;
}
}
inline void floyd(){
for (int k=1;k<=n;k++){
for (int i=1;i<=n;i++){
for (int j=1;j<=n;j++){
if (dis[i][k]+dis[k][j]<dis[i][j])
dis[i][j]=dis[j][i]=dis[i][k]+dis[k][j];
}
}
}
}
inline void p(){
scanf("%d",&k);
while (k--){
scanf("%d%d",&temp1,&temp2);
for (int i=1;i<=n;i++){
if (dis[temp1][i]+dis[i][temp2]==dis[temp1][temp2]){
printf("%d ",i);
}
}
printf("\n");
}
}
int Main(){
readln();
floyd();p();
fclose(stdin);fclose(stdout);
return 0;
}
int main(){;}
int xlm=Main();