Advertisement
999ms

memes

Sep 11th, 2020 (edited)
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define all(x) begin(x),end(x)
  3. #define make_unique(x) sort(all(x)); x.erase(unique(all(x)), end(x))
  4.  
  5. using namespace std;
  6. using ll = long long;
  7.  
  8. const int N = 1e4 + 1;
  9.  
  10. ll a[N];
  11. ll b[N];
  12. ll res[N];
  13. vector<pair<int,int>> rg[N];
  14.  
  15. void dijkstra(int from) {
  16. priority_queue<pair<int, int>> pq;
  17. pq.push({res[from], from});
  18. while (pq.size()) {
  19. auto [w, v] = pq.top();
  20. pq.pop();
  21. if (res[v] > w) continue;
  22. for (auto [to, dw] : rg[v]) {
  23. if (res[to] < res[v] - dw) {
  24. res[to] = res[v] - dw;
  25. pq.push({res[to], to});
  26. }
  27. }
  28. }
  29. }
  30.  
  31. int main() {
  32. int n, m, k;
  33. cin >> n >> m >> k;
  34.  
  35. for (int i = 0; i < n; i++) cin >> b[i];
  36. for (int i = 0; i < n; i++) cin >> a[i];
  37. for (int i = 0; i < n; i++) {
  38. res[i] = b[i];
  39. }
  40. for (int i = 0; i < m; i++) {
  41. int w, f, t;
  42. cin >> w >> f >> t;
  43. f--, t--;
  44. rg[t].emplace_back(f, w);
  45. }
  46.  
  47. vector<int> ind(n);
  48. iota(all(ind), 0);
  49. sort(all(ind), [&] (int i, int j) {
  50. return b[i] > b[j];
  51. });
  52. for (int v : ind) {
  53. dijkstra(v);
  54. }
  55. ll ans = 0;
  56. for (int v : a) {
  57. ans += res[v - 1];
  58. }
  59. cout << ans << '\n';
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement