当前位置: 首页 > 工具软件 > Maelstrom > 使用案例 >

G - MPI Maelstrom floyd atoi()

米楚青
2023-12-01

传送门
题意:因为是无向图,所以给出半个邻接矩阵,让你求1到每个点的最小距离中,最大的那一个距离。
思路:floyd求最短路即可。
知道了一个atoi函数,好用!

/**
* From:
* Qingdao Agricultural University
* Created by XiangwangAcmer
* Date : 2019-10-03-09.33.52
* Talk is cheap.Show me your code.
*/
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<cmath>
#include<cctype>
#include<stack>
#include<map>
#include<string>
#include<cstdlib>
#define ll long long
using namespace std;
const ll maxn = 1e6 + 5;
const ll minn = 1e9 + 5;
const ll mod = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LIMIT = 4294967295LL;
const int N = 301;
//vector<int>v[maxn];
int dp[maxn];
int g[N][N];
bool row[maxn], col[maxn];
bool flag = 0;
int vis[maxn];
queue<int>q;///同dijk实现一样  可以解决负权问题
int n, m;
void floyd() {
    for(int k = 1; k <= n; k++)
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}
int main() {
    ios::sync_with_stdio(false);
    memset(g, 0x3f, sizeof(g));
    cin >> n;
    for(int i = 1; i <= n; i++)
        g[i][i] = 0; ///初始化
    int maxnn = 0;
    int u, v, w;
    char s[maxn];
    for(int i = 2; i <= n; i++)
        for(int j = 1; j < i; j++) {
            cin >> s;
            if(s[0]=='x')
                continue;
            g[j][i] = g[i][j] = atoi(s);
        }
    floyd();
    for(int i = 2; i <= n; i++) {
        if(g[1][i] == INF)
            continue;
        maxnn = max(g[1][i], maxnn);
    }
    cout << maxnn << endl;
    return 0;
}

 类似资料: