Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define all(x) begin(x),end(x)
- #define make_unique(x) sort(all(x)); x.erase(unique(all(x)), end(x))
- using namespace std;
- using ll = long long;
- const int N = 1e4 + 1;
- ll a[N];
- ll b[N];
- ll res[N];
- vector<pair<int,int>> rg[N];
- void dijkstra(int from) {
- priority_queue<pair<int, int>> pq;
- pq.push({res[from], from});
- while (pq.size()) {
- auto [w, v] = pq.top();
- pq.pop();
- if (res[v] > w) continue;
- for (auto [to, dw] : rg[v]) {
- if (res[to] < res[v] - dw) {
- res[to] = res[v] - dw;
- pq.push({res[to], to});
- }
- }
- }
- }
- int main() {
- int n, m, k;
- cin >> n >> m >> k;
- for (int i = 0; i < n; i++) cin >> b[i];
- for (int i = 0; i < n; i++) cin >> a[i];
- for (int i = 0; i < n; i++) {
- res[i] = b[i];
- }
- for (int i = 0; i < m; i++) {
- int w, f, t;
- cin >> w >> f >> t;
- f--, t--;
- rg[t].emplace_back(f, w);
- }
- vector<int> ind(n);
- iota(all(ind), 0);
- sort(all(ind), [&] (int i, int j) {
- return b[i] > b[j];
- });
- for (int v : ind) {
- dijkstra(v);
- }
- ll ans = 0;
- for (int v : a) {
- ans += res[v - 1];
- }
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement