Submission #1163130

#TimeUsernameProblemLanguageResultExecution timeMemory
1163130knot222Construction Project 2 (JOI24_ho_t2)C++20
0 / 100
2 ms4932 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

vector<pair<ll, int>> adj[200005];
int v1[200005];
int v2[200005];
int main()
{
    int N,M,S,T;
    ll L,K;
    cin>>N>>M>>S>>T>>L>>K;
    S--;T--;
    ll d1[N];
    ll d2[N];
    for (int i=0;i<N;i++) {
        d1[N] = LLONG_MAX/2;
        d2[N] = LLONG_MAX/2;
    }
    for (int i=0;i<M;i++) {
        int i1,i2;
        ll i3;
        cin>>i1>>i2>>i3;
        i1--;i2--;
        adj[i1].push_back(make_pair(i3,i2));
        adj[i2].push_back(make_pair(i3,i1));
    }
    d1[S] = 0;
    priority_queue<pair<ll,int>, vector<pair<ll, int>>, greater<pair<int,int>>> pq;
    pq.push(make_pair(0,S));
    while (!pq.empty()) {
        ll l = pq.top().first;
        ll u = pq.top().second;
        pq.pop();
        if (v1[u]) {continue;}
        for (auto pp:adj[u]) {
            if (d1[pp.second]>d1[u]+pp.first) {
                d1[pp.second] = d1[u]+pp.first;
                pq.push(make_pair(d1[u]+pp.first, pp.second));
            }
        }
    }
    pq.push(make_pair(0,T));
    d2[T] = 0;
    while (!pq.empty()) {
        ll l = pq.top().first;
        ll u = pq.top().second;
        pq.pop();
        if (v2[u]) {continue;}
        for (auto pp:adj[u]) {
            if (d2[pp.second]>d2[u]+pp.first) {
                d2[pp.second] = d2[u]+pp.first;
                pq.push(make_pair(d2[u]+pp.first, pp.second));
            }
        }
    }
    sort(d2, d2+N);
    ll ans=0;
    if (d1[T]<=K) {
        cout << (N*(N-1))/2LL;
        return 0;
    }
    for (int i=0;i<N;i++) {
        ans+=max(upper_bound(d2,d2+N, K-L-d1[i])-d2-1, 0L);
    }
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...