fork download
  1. #include <functional>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <utility>
  5. #include <sstream>
  6. #include <iomanip>
  7. #include <numeric>
  8. #include <cstdlib>
  9. #include <cstring>
  10. #include <climits>
  11. #include <cstring>
  12. #include <vector>
  13. #include <cstdio>
  14. #include <string>
  15. #include <stack>
  16. #include <deque>
  17. #include <queue>
  18. #include <cmath>
  19. #include <map>
  20. #include <set>
  21. //#define pb push_back
  22. //#define pf push_front
  23. //#define ppb pop_back
  24. //#define ppf pop_front
  25. #define lwb lower_bound
  26. #define upb upper_bound
  27. #define F first
  28. #define S second
  29. //#define FOR(i,j,k) for(int i = j; i < (int)(k); i++)
  30. //#define FORV(i, v) FOR(i, 0, ((v).size()))
  31. //#define sz(a) (int)((a).size())
  32. //#define all(a) a.begin() , a.end()
  33. #define coud(a,b) cout<<fixed << setprecision((b)) << (a)
  34. #define L(x) ((x)<<1)
  35. #define R(x) (((x)<<1)+1)
  36. //#define int long long
  37. #define double long double
  38. #define joon ios :: sync_with_stdio(false)
  39. //#define cin fin
  40. //#define cout fout
  41.  
  42. using namespace std;
  43.  
  44. typedef pair<int, int> pii;
  45. typedef long long ll;
  46. const double pi = acos(-1);
  47. const double eps = 1e-7;
  48. const int MAXN=50000+100;
  49. const int INF=1000*1000*1000;
  50. priority_queue< pair<int,int> , vector< pair<int,int> > , less<pair<int,int> > > q;
  51. vector< pair<int,int> > N[MAXN];
  52. int ki[MAXN];
  53. bool mark[MAXN],isk[MAXN];
  54. int anss[MAXN],d[MAXN];
  55. int ans,k,n,m,t;
  56.  
  57. void dijkstra(int v)
  58. {
  59. q.push( make_pair(d[v],v) );
  60. while( !q.empty() )
  61. {
  62. pair<int,int> u=q.top();
  63. q.pop();
  64. if( mark[ u.S ]==0 && u.F < k )
  65. {
  66. mark[ u.S ]=1;
  67. ans++;
  68. }
  69. for(int i=0;i<(int)N[ u.S ].size();i++)
  70. if( d[ N[ u.S ][i].F ] > d[u.S] + N[ u.S ][i].S )
  71. {
  72. d[ N[ u.S ][i].F ] = d[u.S] + N[ u.S ][i].S;
  73. if( d[ N[ u.S ][i].F ] < k )
  74. q.push( make_pair( d[ N[ u.S ][i].F ] , N[ u.S ][i].F ) );
  75. }
  76. }
  77. }
  78.  
  79. int main()
  80. {
  81. joon;
  82. cin.tie(0);
  83.  
  84. cin>>n>>m>>t>>k;
  85. for(int i=1;i<=m;i++)
  86. {
  87. int v,u,w;
  88. cin>>v>>u>>w;
  89. N[v].push_back( make_pair(u,w) );
  90. N[u].push_back( make_pair(v,w) );
  91. }
  92. for(int i=1;i<=t;i++)
  93. cin>>ki[i];
  94. for(int i=1;i<=n;i++)
  95. d[i]=k;
  96. for(int i=1;i<=t;i++)
  97. {
  98. d[ ki[i] ]=0;
  99. dijkstra( ki[i] );
  100. anss[i]=n-ans;
  101. }
  102. for(int i=1;i<=t;i++)
  103. cout<<anss[i]<<"\n";
  104.  
  105. return 0;
  106. }
  107.  
Success #stdin #stdout 0s 4684KB
stdin
Standard input is empty
stdout
Standard output is empty