fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #ifdef LOCAL
  5. #define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__)
  6. #else
  7. #define DEBUG(...) 6
  8. #endif
  9.  
  10. template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
  11. template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
  12. ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
  13. template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
  14. template <typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
  15. if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << s.substr(0, i) << " = " << x << " | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}
  16.  
  17. typedef tuple<int, int, int> node;
  18.  
  19. int main() {
  20. ios_base::sync_with_stdio(false);
  21. cin.tie(NULL);
  22.  
  23. int n, m, a, k;
  24. bool f = true;
  25. while (cin >> n >> m >> a >> k, n || m || a || k) {
  26. if (f) f = false;
  27. else cout << "\n";
  28.  
  29. vector<vector<pair<int, int>>> adj(n);
  30. for (int i=0; i<m; i++) {
  31. int u, v, d;
  32. cin >> u >> v >> d;
  33. u--, v--;
  34. adj[u].emplace_back(v, d);
  35. adj[v].emplace_back(u, d);
  36. }
  37.  
  38. vector<vector<int>> mn(n, vector<int>(k, a));
  39. priority_queue<node, vector<node>, greater<node>> pq;
  40. for (int i=0; i<a; i++) {
  41. int b;
  42. cin >> b;
  43. b--;
  44. if (mn[b][0] == a)
  45. pq.emplace(mn[b][0] = i, b, 0);
  46. }
  47. while (!pq.empty()) {
  48. auto [id, u, d] = pq.top();
  49. pq.pop();
  50. if (id > mn[u][d])
  51. continue;
  52. for (auto [v, w] : adj[u])
  53. if (d + w < k && id < mn[v][d + w])
  54. pq.emplace(mn[v][d + w] = id, v, d + w);
  55. }
  56.  
  57. vector<int> rem(a + 1);
  58. for (int u=0; u<n; u++)
  59. rem[*min_element(mn[u].begin(), mn[u].end())]++;
  60.  
  61. int ret = n;
  62. for (int i=0; i<a; i++) {
  63. ret -= rem[i];
  64. cout << ret << "\n";
  65. }
  66. }
  67.  
  68. return 0;
  69. }
  70.  
Runtime error #stdin #stdout 0.64s 2096132KB
stdin
Standard input is empty
stdout
Standard output is empty