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

4 篇文章 0 订阅
2 篇文章 0 订阅

传送门: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 V (Numbers 1 to V V V) fire-fighting points in ACM city. These fire-fighting points have E E E roads to communicate with each other. Among them, there is a fire-fighting hero in the S S S fire-fighting point, and the fire-fighting team is distributed in K 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} C1 , 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) T(1T10), 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) V(1V1000),E(V1E2VV),S(1SV)S(1SV),K(1KV) and C ( 1 ≤ C ≤ 10 ) C (1\le C\le 10) C(1C10), the meanings are shown above.
Line 2 contains K 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) i,j(1i,jV)i,j(1i,jV) and L ( 1 ≤ L ≤ 10000 ) L ( 1 ≤ L ≤ 10000 ) L (1 \le L \le 10000)L(1≤L≤10000) L(1L10000)L(1L10000) 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;
}
        
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值