You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
735 B
38 lines
735 B
#include <bits/stdc++.h>
|
|
/**
|
|
5 4
|
|
1 2
|
|
1 3
|
|
2 4
|
|
2 5
|
|
答案
|
|
2 1 3 2
|
|
*
|
|
*/
|
|
using namespace std;
|
|
const int INF = 0x3f3f3f3f;
|
|
const int N = 110;
|
|
int d[N][N];
|
|
int n, m;
|
|
void floyd() {
|
|
for (int k = 0; k < n; k++)
|
|
for (int i = 1; i <= n; i++)
|
|
for (int j = 1; j <= n; j++)
|
|
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
|
|
}
|
|
int main() {
|
|
cin >> n >> m;
|
|
memset(d, 0x3f, sizeof d);
|
|
for (int i = 0; i < m; i++) {
|
|
int a, b;
|
|
cin >> a >> b;
|
|
d[a][b] = d[b][a] = 1;
|
|
}
|
|
floyd();
|
|
for (int i = 1; i < n; i++)
|
|
if (d[n][i] == INF)
|
|
cout << -1 << " ";
|
|
else
|
|
cout << d[n][i] << " ";
|
|
return 0;
|
|
} |