zoukankan      html  css  js  c++  java
  • Codeforces 449B

    题目链接

    B. Jzzhu and Cities
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are mroads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this road is xi. Finally, there are k train routes in the country. One can use the i-th train route to go from capital of the country to city si (and vise versa), the length of this route is yi.

    Jzzhu doesn't want to waste the money of the country, so he is going to close some of the train routes. Please tell Jzzhu the maximum number of the train routes which can be closed under the following condition: the length of the shortest path from every city to the capital mustn't change.

    Input

    The first line contains three integers n, m, k (2 ≤ n ≤ 105; 1 ≤ m ≤ 3·105; 1 ≤ k ≤ 105).

    Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ nui ≠ vi; 1 ≤ xi ≤ 109).

    Each of the next k lines contains two integers si and yi (2 ≤ si ≤ n; 1 ≤ yi ≤ 109).

    It is guaranteed that there is at least one way from every city to the capital. Note, that there can be multiple roads between two cities. Also, there can be multiple routes going to the same city from the capital.

    Output

    Output a single integer representing the maximum number of the train routes which can be closed.

    Sample test(s)
    input
    5 5 3
    1 2 1
    2 3 2
    1 3 3
    3 4 4
    1 5 5
    3 5
    4 5
    5 5
    output
    2
    input
    2 2 3
    1 2 2
    2 1 3
    2 1
    2 2
    2 3
    output
    2
    
    
     1 /*************************************************************************
     2     > File Name: 449B.cpp
     3     > Author: Stomach_ache
     4     > Mail: sudaweitong@gmail.com
     5     > Created Time: 2014年07月20日 星期日 10时17分44秒
     6     > Propose: 
     7  ************************************************************************/
     8 #include <queue>
     9 #include <cmath>
    10 #include <vector>
    11 #include <string>
    12 #include <cstdio>
    13 #include <fstream>
    14 #include <cstring>
    15 #include <iostream>
    16 #include <algorithm>
    17 using namespace std;
    18 
    19 #define X first
    20 #define Y second
    21 const int maxn = 100005;
    22 typedef long long LL;
    23 typedef pair<LL, int> pii;
    24 LL d[maxn];
    25 int n, m, k;
    26 bool done[maxn];
    27 vector<pii> G[maxn];
    28 
    29 void
    30 dijkstra() {
    31     priority_queue<pii> q;
    32     d[0] = 0;
    33     for (int i = 0; i < n; i++) if (d[i] != 1e15) q.push(pii(-d[i], i));
    34     //memset(done, false, sizeof(done));
    35     while (!q.empty()) {
    36         pii cur = q.top();
    37         q.pop();
    38         int r = -cur.X;
    39         int u = cur.Y;
    40         if (r != d[u]) continue;
    41         for (unsigned i = 0; i < G[u].size(); i++) {
    42             int v = G[u][i].X;
    43             if (d[v] > d[u] + G[u][i].Y) {
    44                 d[v] = d[u] + G[u][i].Y;
    45                 q.push(pii(-d[v], v));
    46             }
    47         }
    48     }
    49 
    50     return ;
    51 }
    52 
    53 int
    54 main(void) {
    55     ios::sync_with_stdio(false);
    56     cin >> n >> m >> k;
    57     for (int i = 0; i < m; i++) {
    58         int u, v, x;
    59         cin >> u >> v >> x;
    60         u--, v--;
    61         G[u].push_back(pii(v, x));
    62         G[v].push_back(pii(u, x));
    63     }
    64     for (int i = 0; i < n; i++) d[i] = 1e15;
    65     for (int i = 0; i < k; i++) {
    66         int s, y;
    67         cin >> s >> y;
    68         s--;
    69         d[s] = min(d[s], y*1LL);
    70     }
    71     dijkstra();
    72 
    73     int res = 0;
    74     for (int i = 1; i < n; i++) {
    75           int t = 1;
    76           for (unsigned j = 0; j < G[i].size(); j++) {
    77               if (d[i] == d[G[i][j].X] + G[i][j].Y) {
    78                 t = 0;
    79                 break;
    80             }
    81         }
    82        res += t;
    83     }
    84     cout << k - res << endl;
    85 
    86     return 0;
    87 }
    
    
    
    
    
    
    
    
    
    
    
    
    
  • 相关阅读:
    概念
    Jquery和Aspnet前台控件及后台代码交互
    未能找到引用的组件“Microsoft.Office.Core
    C#操作Excel,调用ApplicationClass.Quit()关闭Excel时,发生异常:Microsoft Office Word 遇到问题需要关闭
    Javasrcipt捕获按键
    使用Interop.Excel生成Excel
    Javasrcipt时间相关函数
    (转)各种纹理贴图技术
    (转)立体纹理
    (转)地形碰撞高度计算
  • 原文地址:https://www.cnblogs.com/Stomach-ache/p/3857401.html
Copyright © 2011-2022 走看看