제출 #1260697

#제출 시각아이디문제언어결과실행 시간메모리
1260697luyendhqnConstruction Project 2 (JOI24_ho_t2)C++20
100 / 100
131 ms24924 KiB
//vmaskimoski #include <bits/stdc++.h> #define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; int32_t main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); int n, m, s, t, L, k, ans = 0; cin >> n >> m >> s >> t >> L >> k; vector<pii> graph[n+1]; for(int i=0; i<m; i++) { int a, b, w; cin >> a >> b >> w; graph[a].push_back({ b, w }); graph[b].push_back({ a, w }); } auto dijkstra = [&](int start) { vector<bool> vis(n+1); vector<ll> dist(n+1, 1e18); priority_queue<pll, vector<pll>, greater<pll> > pq; dist[start] = 0; pq.push({ 0, start }); while(!pq.empty()) { int u = pq.top().second; pq.pop(); if(vis[u]) continue; vis[u] = 1; for(auto &[v, w] : graph[u]) { if(dist[v] > dist[u] + w) { dist[v] = dist[u] + w; pq.push({ dist[v], v }); } } } return dist; }; vector<ll> D1 = dijkstra(s); vector<ll> D2 = dijkstra(t); if(D1[t] <= k) { cout << 1ll * n * (n - 1) / 2 << '\n'; return 0; } vector<pll> D; for(int i=1; i<=n; i++) D.push_back({ D2[i], D1[i] }); sort(D.begin(), D.end()); for(int i=1; i<n; i++) { int l=0, r=i-1, p=-1; while(l <= r) { int mid = (l + r) / 2; if(D[i].second + L + D[mid].first <= k) p = mid, l = mid + 1; else r = mid - 1; } ans += p + 1; } cout << ans << '\n'; 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...