Submission #1245386

#TimeUsernameProblemLanguageResultExecution timeMemory
1245386RecursiveCoConstruction Project 2 (JOI24_ho_t2)C++20
100 / 100
224 ms23724 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define in(i) cin >> i
#define out(o) cout << o

// vector<int>

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N, M, S, T, L, K;
    in(N);
    in(M);
    in(S);
    in(T);
    in(L);
    in(K);
    --S;
    --T;
    vector<vector<pair<int, int>>> adjList(N);
    for (int i = 0; i < M; ++i) {
        int a, b, w;
        in(a);
        in(b);
        in(w);
        --a;
        --b;
        adjList[a].push_back({b, w});
        adjList[b].push_back({a, w});
    }
    vector<int> F(N, 1e18);
    vector<int> G(N, 1e18);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    pq.push({0, S});
    while (!pq.empty()) {
        pair<int, int> top = pq.top();
        int d = top.first;
        int v = top.second;
        pq.pop();
        if (F[v] != 1e18) continue;
        F[v] = d;
        for (pair<int, int> con: adjList[v]) {
            if (F[con.first] == 1e18) pq.push({d + con.second, con.first});
        }
    }
    while (!pq.empty()) pq.pop();
    pq.push({0, T});
    while (!pq.empty()) {
        pair<int, int> top = pq.top();
        int d = top.first;
        int v = top.second;
        pq.pop();
        if (G[v] != 1e18) continue;
        G[v] = d;
        for (pair<int, int> con: adjList[v]) {
            if (G[con.first] == 1e18) pq.push({d + con.second, con.first});
        }
    }
    if (F[T] <= K) {
        out(N * (N - 1) / 2);
        return 0;
    }
    sort(F.begin(), F.end());
    sort(G.begin(), G.end());
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        int f = F[i];
        auto it = upper_bound(G.begin(), G.end(), K - L - f);
        ans += it - G.begin();
    }
    out(ans);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...