제출 #1323186

#제출 시각아이디문제언어결과실행 시간메모리
1323186aryanConstruction Project 2 (JOI24_ho_t2)C++20
100 / 100
162 ms23324 KiB
#include<bits/stdc++.h> using namespace std; using i64 = long long; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,m; cin >> n >> m; int s,t,l; i64 k; cin >> s >> t >> l >> k; s --; t --; vector<vector<pair<int,int>>> adj(n); for(int i = 0;i < m;i++){ int u,v,w; cin >> u >> v >> w; u --; v --; adj[u].push_back({v,w}); adj[v].push_back({u,w}); } const i64 inf = 1e18; function<vector<i64>(int)> f = [&](int src){ vector<i64> dist(n,inf); priority_queue<pair<i64,int>,vector<pair<i64,int>>,greater<pair<i64,int>>> pq; pq.push({0,src}); dist[src] = 0; while(!pq.empty()){ int u = pq.top().second; i64 w = pq.top().first; pq.pop(); if(dist[u] < w) continue; for(auto p : adj[u]){ int v = p.first; if(p.second + w < dist[v]){ dist[v] = p.second + w; pq.push({dist[v],v}); } } } return dist; }; vector<i64> d_s = f(s); vector<i64> d_t = f(t); vector<i64> d_ss = d_s; vector<i64> d_ts = d_t; sort(d_ss.begin(),d_ss.end()); sort(d_ts.begin(),d_ts.end()); i64 ans = 0; for(int i = 0;i < n;i++){ // if this node is involved in the extra i64 ds = d_s[i]; i64 dt = d_t[i]; // if s -> i -> v -> t { i64 d = ds + l; // we want that d + x <= k // x <= k - d int up = upper_bound(d_ts.begin(),d_ts.end(),k - d) - d_ts.begin(); ans += up; } { i64 d = dt + l; // we want that d + x <= k // x <= k - d int up = upper_bound(d_ss.begin(),d_ss.end(),k - d) - d_ss.begin(); ans += up; } } if(d_s[t] <= k){ ans = n * 1LL * (n - 1); } cout << ans / 2 << '\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...