编程介的小学生 2019-12-31 17:54 采纳率: 0.2%
浏览 68

Portal 的问题

Problem Description
ZLGG found a magic theory that the bigger banana the bigger banana peel .This important theory can help him make a portal in our universal. Unfortunately, making a pair of portals will cost min{T} energies. T in a path between point V and point U is the length of the longest edge in the path. There may be lots of paths between two points. Now ZLGG owned L energies and he want to know how many kind of path he could make.

Input
There are multiple test cases. The first line of input contains three integer N, M and Q (1 < N ≤ 10,000, 0 < M ≤ 50,000, 0 < Q ≤ 10,000). N is the number of points, M is the number of edges and Q is the number of queries. Each of the next M lines contains three integers a, b, and c (1 ≤ a, b ≤ N, 0 ≤ c ≤ 10^8) describing an edge connecting the point a and b with cost c. Each of the following Q lines contain a single integer L (0 ≤ L ≤ 10^8).

Output
Output the answer to each query on a separate line.

Sample Input
10 10 10
7 2 1
6 8 3
4 5 8
5 8 2
2 8 9
6 4 5
2 1 5
8 10 5
7 3 7
7 8 8
10
6
1
5
9
1
8
2
7
6

Sample Output
36
13
1
13
36
1
36
2
16
13

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-07-27 11:11
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1e5 + 10;
    int n,m,q,l;
    vector<int>adj[maxn];
    int dis[maxn],f[maxn];
    void dijkstra(int s){
        priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> q;
        memset(dis,-1,sizeof(dis));
        dis[s] = 0;
        q.push(make_pair(0,s));
        while(!q.empty()){
            auto t = q.top();
            q.pop();
            if(t.first > dis[t.second]) continue;
            for(auto &u: adj[t.second]){
                if(dis[u] <= -t.first + f[u]) continue;
                dis[u] = -t.first + f[u];
                q.push(make_pair(-dis[u],u));
            }
        }
    }
    int main(){
        cin >> n >> m >> q;
        l = 0;
        for(int i=1;i<=m;++i){
            int u,v,c;
            cin >> u >> v >> c;
            adj[u].push_back(v);
            adj[v].push_back(u);
            ++l;
        }
        for(int i=1;i<=n;++i){
            for(int j=0;j<adj[i].size();++j){
                int u = adj[i][j];
                f[u] += c;
            }
        }
        for(int i=1;i<=n;++i){
            if(l == 1 && i != 1) break;
            dijkstra(i);
            cout << dis[n] << endl;
        }
        return 0;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上