Submission #1127535

#TimeUsernameProblemLanguageResultExecution timeMemory
112753512345678Construction Project 2 (JOI24_ho_t2)C++17
100 / 100
221 ms25824 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=2e5+5; ll n, m, s, t, l, k, u, v, w, a[nx], b[nx], ans, vs[nx]; vector<pair<ll, ll>> d[nx]; priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq; vector<ll> vl; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>m>>s>>t>>l>>k; for (int i=1; i<=m; i++) cin>>u>>v>>w, d[u].push_back({v, w}), d[v].push_back({u, w}); for (int i=1; i<=n; i++) a[i]=b[i]=LLONG_MAX; a[s]=b[t]=0; pq.push({0, s}); while (!pq.empty()) { auto [w, u]=pq.top(); pq.pop(); if (vs[u]) continue; vs[u]=1; for (auto [v, nw]:d[u]) if (w+nw<a[v]) a[v]=w+nw, pq.push({w+nw, v}); } if (a[t]<=k) return cout<<(n*(n-1))/2, 0; pq.push({0, t}); for (int i=1; i<=n; i++) vs[i]=0; while (!pq.empty()) { auto [w, u]=pq.top(); pq.pop(); if (vs[u]) continue; vs[u]=1; for (auto [v, nw]:d[u]) if (w+nw<b[v]) b[v]=w+nw, pq.push({w+nw, v}); } for (int i=1; i<=n; i++) vl.push_back(b[i]); sort(vl.begin(), vl.end()); for (int i=1; i<=n; i++) if (a[i]!=LLONG_MAX) ans+=(upper_bound(vl.begin(), vl.end(), k-a[i]-l)-vl.begin()); cout<<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...