Submission #1100568

#TimeUsernameProblemLanguageResultExecution timeMemory
1100568vjudge1Construction Project 2 (JOI24_ho_t2)C++17
100 / 100
198 ms31416 KiB
#include<bits/stdc++.h> #define int long long #define fi first #define se second #define pb push_back #define ii pair<int, int> #define sz(v) (int)v.size() #define all(v) v.begin(), v.end() using namespace std; const int N=2e5+5, mod = 1e9+7, inf = 1e18; int n, m, s, t, l, k; int ds[N], dt[N]; vector<ii> adj[N]; priority_queue<ii,vector<ii>,greater<ii>> pq; signed main() { //freopen("tmp.inp", "r", stdin); //freopen("tmp.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> s >> t >> l >> k; for(int i=1; i<=m; i++) { int a, b, c; cin >> a >> b >> c; adj[a].push_back({b, c}); adj[b].push_back({a, c}); } for (int i=1; i<=n; i++) ds[i] = inf; ds[s] = 0; pq.push({0, s}); while(!pq.empty()) { int u = pq.top().se, d = pq.top().fi; pq.pop(); if(d>ds[u]) continue; for (auto [v, w]: adj[u]) { if(ds[v]>ds[u]+w) { ds[v] = ds[u]+w; pq.push({ds[v], v}); } } } for (int i=1; i<=n; i++) dt[i] = inf; dt[t] = 0; pq.push({0, t}); while(!pq.empty()) { int u = pq.top().se, d = pq.top().fi; pq.pop(); if(d>dt[u]) continue; for (auto [v, w]: adj[u]) { if(dt[v]>dt[u]+w) { dt[v] = dt[u]+w; pq.push({dt[v], v}); } } } for(int i=1; i<=n; i++) { if(ds[i]+dt[i]<=k) { cout << n*(n-1)/2; return 0; } } int ans = 0; sort(ds+1, ds+n+1); sort(dt+1, dt+n+1); for(int i=1; i<=n; i++) { int pos = upper_bound(dt+1, dt+n+1, k-l-ds[i])-dt-1; ans += pos; } 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...