Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define MAXN 100005
  3. #define INF 0x3f3f3f3f
  4. using namespace std;
  5. long long n, m, k, d[MAXN], viz[MAXN], s;
  6. struct edge
  7. {
  8. char special; // 0 - normal, 1 - special
  9. long long nod,c;
  10. edge(long long nod, long long c, char special):nod(nod),c(c),
  11. special(special) {}
  12. bool operator<(const edge &oth) const
  13. {
  14. if(c == oth.c) {
  15. if(special == 1)
  16. return -1;
  17. }
  18. return c>oth.c;
  19. }
  20. };
  21. vector<edge> v[MAXN];
  22. priority_queue<edge> pq;
  23. void djikstra(long long start)
  24. {
  25.  
  26. for(long long i=1; i<=n; ++i) {
  27. d[i]=INF;
  28. viz[i] = 0;
  29. }
  30. d[start]=0;
  31. pq.push(edge(start,0,0));
  32. while(!pq.empty())
  33. {
  34. long long nod = pq.top().nod;
  35. long long cost = pq.top().c;
  36. long long special = pq.top().special;
  37. //cout << "nod : " << nod << " special " << special << endl;
  38. pq.pop();
  39. if(viz[nod] == 0) {
  40. viz[nod] = 1;
  41. for(edge i : v[nod]) {
  42. if(d[nod] + i.c < d[i.nod]) {
  43. d[i.nod] = d[nod] + i.c;
  44. if(i.special) {
  45. ++s;
  46. }
  47. pq.push(edge(i.nod, d[i.nod], 0));
  48. }
  49. }
  50. }
  51. }
  52. }
  53. int main()
  54. {
  55. cin>>n>>m>>k;
  56. s = 0;
  57. for(long long i=1; i<=m; ++i)
  58. {
  59. long long a,b,c;
  60. cin>>a>>b>>c;
  61. v[a].push_back(edge(b, c, 0));
  62. }
  63. for(long long i = 1; i <= k; ++i)
  64. {
  65. long long a, b;
  66. cin >> a >> b;
  67. d[a] = b;
  68. v[1].push_back(edge(a, b, 1));
  69. // pq.push(edge(a,b,1));
  70. }
  71. djikstra(1);
  72. cout << k - s << endl;
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement