记录编号 563013 评测结果 AAAAAAAAAA
题目名称 找最佳通路 最终得分 100
用户昵称 GravatarZooxTark➲ 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2021-07-10 17:06:23 内存使用 0.00 MiB
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int g[60][60] = {0};
int n,m,s,e;

int main()
{
    freopen("city.in","r",stdin);
    freopen("city.out","w",stdout);
    cin >> n >> m >> s >> e;
    memset(g,0x3f,sizeof(g));
    for(int i = 0,a,b;i < m;i++)
    {
        cin >> a >> b;
        g[a][b] = g[b][a] = 1;
    }
    for(int k = 1;k <= n;k++)
    {
        for(int i = 1;i <= n;i++)
        {
            for(int j = 1;j <= n;j++)
            {
                if(g[i][j] > g[i][k] + g[k][j])
                {
                    g[i][j] = g[i][k] + g[k][j];
                }
            }
        }
    }
    cout << g[s][e]+1;
    return 0;
}