Submission #1139018

#TimeUsernameProblemLanguageResultExecution timeMemory
1139018ByeWorldConstruction Project 2 (JOI24_ho_t2)C++20
100 / 100
314 ms33856 KiB
#include <bits/stdc++.h> #define int long long #define ll long long #define pb push_back #define fi first #define se second #define lf (id<<1) #define rg ((id<<1)|1) #define md ((l+r)>>1) #define ld long double using namespace std; typedef pair<int,int> pii; typedef pair<char,char> pcc; typedef pair<int,pii> ipii; typedef pair<pii,pii> ipiii; const int MAXN = 3e5+50; const int SQRT = 610; const int MAXA = 50; const int MOD = 998244353; const int LOG = 21; const int INF = 1e16+100; const int INF2 = 1e18; const ld EPS = 1e-12; int n, m, s, t, l, k; vector <pii> adj[MAXN]; priority_queue <pii, vector<pii>, greater<pii>> pq; int dis[MAXN], dis2[MAXN]; void dji2(){ for(int i=1; i<=n; i++) dis2[i] = INF; dis2[t] = 0; pq.push({0, t}); while(!pq.empty()){ int nw = pq.top().se, dist = pq.top().fi; pq.pop(); if(dist > dis2[nw]) continue; for(auto [nx, ed] : adj[nw]){ if(dis2[nx] > dist+ed){ dis2[nx] = dist+ed; pq.push({dis2[nx], nx}); } } } } void dji(){ for(int i=1; i<=n; i++) dis[i] = INF; dis[s] = 0; pq.push({0, s}); while(!pq.empty()){ int nw = pq.top().se, dist = pq.top().fi; pq.pop(); if(dist > dis[nw]) continue; for(auto [nx, ed] : adj[nw]){ if(dis[nx] > dist+ed){ dis[nx] = dist+ed; pq.push({dis[nx], nx}); } } } } struct seg { int st[4*MAXN]; int que(int id, int l, int r, int x, int y){ if(x<=l && r<=y) return st[id]; if(r<x || y<l) return 0; return que(lf,l,md,x,y) + que(rg,md+1,r,x,y); } int upd(int id, int l, int r, int x, int p){ if(l==r && l==x) return st[id] += p; if(r<x || x<l) return st[id]; return st[id] = upd(lf,l,md,x,p) + upd(rg,md+1,r,x,p); } } A; vector <pii> que[MAXN]; signed main(){ // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n>>m; cin>>s>>t>>k>>l; for(int i=1; i<=m; i++){ int x, y, z; cin>>x>>y>>z; adj[x].pb({y,z}); adj[y].pb({x,z}); } dji(); dji2(); // for(int i=1; i<=n; i++){ // cout << i << ' ' <<dis[i]<<' '<<dis2[i]<< "pp\n"; // } if(dis[t] <= l){ cout << n*(n-1)/2 << '\n'; exit(0); } vector <int> vec; for(int i=1; i<=n; i++) vec.pb(dis2[i]); sort(vec.begin(), vec.end()); int ans = 0; for(int i=1; i<=n; i++){ int te = l-k-dis[i]; int xx =upper_bound(vec.begin(), vec.end(), te) - vec.begin(); // cout << i << ' ' << xx << "xx\n"; ans += xx; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...