比赛 20160923 评测结果 AAAAAAAAA
题目名称 道路重建 最终得分 100
用户昵称 KZNS 运行时间 0.025 s
代码语言 C++ 内存使用 0.30 MiB
提交时间 2016-09-23 20:22:18
显示代码纯文本
//KZNS
#include <cstdio>
#include <algorithm>
using namespace std;
#define INF 0x3fffffff
int N;
int M;
int dis[103][103];
bool de[103][103] = {false};
int S, T;
void rin() {
    scanf("%d", &N);
    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= N; j++)
            dis[i][j] = INF;
    scanf("%d", &M);
    int a, b, c;
    for (int i = 0; i < M; i++) {
        scanf("%d %d %d", &a, &b, &c);
        dis[a][b] = min(dis[a][b], c);
        dis[b][a] = min(dis[b][a], c);
    }
    scanf("%d", &M);
    for (int i = 0; i < M; i++) {
        scanf("%d %d", &a, &b);
        de[a][b] = de[b][a] = true;
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            if (!de[i][j]) {
                if (dis[i][j] == INF)
                    continue;
                dis[i][j] = 0;
            }
        }
    }
    scanf("%d %d", &S, &T);
}
void work() {
    for (int k = 1; k <= N; k++) {
        for (int i = 1; i <= N; i++) {
            if (k == i)
                continue;
            for (int j = 1; j <= N; j++) {
                if (k == j || i == j)
                    continue;
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
            }
        }
    }
    printf("%d\n", dis[S][T]);
}
int main() {
    freopen("rebuild.in", "r", stdin);
    freopen("rebuild.out", "w", stdout);
    rin();
    work();
    return 0;
}
//UBWH