The 2019 Aisa Nanchang First Round Online Programming Contest B. Fire-Fighting Hero (最短路+超级源点)

传送门:https://nanti.jisuanke.com/t/41349

Description

This is an era of team success, but also an era of heroes. Throughout the ages, there have been numerous examples of using the few to defeat the many. There are V V (Numbers 1 to V V ) fire-fighting points in ACM city. These fire-fighting points have E E roads to communicate with each other. Among them, there is a fire-fighting hero in the S S fire-fighting point, and the fire-fighting team is distributed in K K fire-fighting points. If a fire-fighting point needs to be put out, the fire-fighting hero or the fire-fighting team must arrive as soon as possible, that is, to choose the shortest route to arrive.

Today, our fire-fighting heroes want to challenge the fire-fighting team. The challenge is to: The maximum value of the shortest path for a fire-fighting hero to go to others fire-fighting points is compared with the maximum value of the shortest path for a fire-fighting team to go to others fire-fighting points from any point in their fire-fighting points. Because firefighting heroes are different and run faster, the maximum value of the shortest path they get should be discounted first, that is, multiplied by a coefficient of 1 C \frac{1}{C} , and then compared. The smaller one wins. Who is the real firefighter in this situation?

Input

The first line contains a positive integer T ( 1 T 10 ) T (1\le T \le 10) , which indicates that there are TT cases of test data.

The format of each case of test data is as follows:

Line 11 contains five positive integers V ( 1 V 1000 ) , E ( V 1 E V V 2 ) , S ( 1 S V ) S ( 1 S V ) , K ( 1 K V ) V (1 \le V \le 1000), E (V-1 \le E \le \frac{V*V}{2}), S (1 \le S \le V)S(1≤S≤V), K (1\le K \le V) and C ( 1 C 10 ) C (1\le C\le 10) , the meanings are shown above.
Line 2 contains K K positive integers, which in turn denotes the location number of the fire-fighting point where the fire-fighting team is located.
In the next EE line, three positive integers i , j ( 1 i , j V ) i , j ( 1 i , j V ) i, j (1 \le i, j \le V)i,j(1≤i,j≤V) and L ( 1 L 10000 ) L ( 1 L 10000 ) L (1 \le L \le 10000)L(1≤L≤10000) per line. Represents a path, i, ji,j as the endpoint (fire-fighting point), LL as the length of the path.

Output

Each case of test data outputs one line, which is a integer. That is, the maximum value of the shortest path of the winner (If the fire hero wins, the maximum value before the discount should be output). A draw is also a victory for fire-fighting hero.

Sample Input

1
4 7 3 2 2
1 4
1 2 7
1 3 2
1 4 6 
2 1 1
2 4 1
3 2 1
3 4 3

Sample Output

2

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

 

const int maxn = 1e3 + 10;

const int maxm = 1e6 + 10;

bool vis[maxn];

int t, n, m, s, k, c, cnt, head[maxn], team_id[maxn];

ll dis[maxn], team_dis[maxn];

struct edge { int v, next; ll w; } e[maxm];

struct node

{

    int u; ll w;

    bool operator < (const node &n) const { return w > n.w; }

};

priority_queue<node> q;

 

inline const int read()

{

    int x = 0, f = 1;

    char ch = getchar();

    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }

    while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); }

    return x * f;

}

 

void addedge(int u, int v, int w)

{

    e[cnt].v = v;

    e[cnt].w = w;

    e[cnt].next = head[u];

    head[u] = cnt++;

}

 

void dijkstra(int src)

{

    memset(dis, 0x3f, sizeof(dis));

    memset(vis, false, sizeof(vis));

    dis[src] = 0;

    q.push(node{src, 0});

    while (!q.empty())

    {

        int u = q.top().u; q.pop();

        if (vis[u]) continue;

        vis[u] = true;

        for (int i = head[u]; ~i; i = e[i].next)

        {

            int v = e[i].v;

            ll w = e[i].w;

            if (dis[v] > dis[u] + w)

            {

                dis[v] = dis[u] + w;

                q.push(node{v, dis[v]});

            }

        }

    }

}

 

int main()

{

    t = read();

    while (t--)

    {

        cnt = 0;

        memset(head, -1, sizeof(head));

        

        n = read(); m = read(); s = read(); k = read(); c = read();

        for (int i = 0; i < k; i++) addedge(0,read(),0);

        for (int i = 0; i < m; i++)
        {
            int u = read(), v = read(), w = read();
            addedge(u, v, w); addedge(v, u, w);
        }
        
        
        dijkstra(s);
        
        ll hero_res = 0;
        for (int i = 1; i <= n; i++) hero_res = max(hero_res, dis[i]);
        dijkstra(0);
        ll team_res = 0;
        for (int i = 1; i <= n; i++) team_res = max(team_res, dis[i]);
        printf("%lld\n", hero_res <= team_res * c ? hero_res : team_res);
    }
    return 0;
}
        
发布了35 篇原创文章 · 获赞 15 · 访问量 1113

猜你喜欢

转载自blog.csdn.net/irimsky/article/details/100941911