# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1111257 | StefanSebez | Construction Project 2 (JOI24_ho_t2) | C++14 | 5 ms | 5456 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
const int N=2e5+50;
const ll inf=1e18;
vector<pair<ll,ll>>E[N];
ll dist[N][2];bool was[N];
priority_queue<pair<ll,ll>>kju;
int main(){
int n,m;scanf("%i%i",&n,&m);
int S,T;ll L,K;scanf("%i%i%lld%lld",&S,&T,&L,&K);
for(int i=1;i<=m;i++){
int u,v;ll w;scanf("%i%i%lld",&u,&v,&w);
E[u].pb({v,w}),E[v].pb({u,w});
}
for(int i=1;i<=n;i++) dist[i][0]=dist[i][1]=inf;
dist[S][0]=0;
kju.push({0,S});
while(kju.size()){
int u=kju.top().se;kju.pop();
if(was[u]) continue;
was[u]=true;
for(auto i:E[u]){
if(!was[i.fi]&&dist[i.fi][0]>dist[u][0]+i.se){
dist[i.fi][0]=dist[u][0]+i.se;
kju.push({-dist[i.fi][0],i.fi});
}
}
}
for(int i=1;i<=n;i++) was[i]=false;
dist[T][1]=0;
kju.push({0,T});
while(kju.size()){
int u=kju.top().se;kju.pop();
if(was[u]) continue;
was[u]=true;
for(auto i:E[u]){
if(!was[i.fi]&&dist[i.fi][1]>dist[u][1]+i.se){
dist[i.fi][1]=dist[u][1]+i.se;
kju.push({-dist[i.fi][1],i.fi});
}
}
}
//for(int i=1;i<=n;i++) printf("%i: %lld %lld\n",i,dist[i][0],dist[i][1]);
ll A[n+10],B[n+10];
for(int i=1;i<=n;i++) A[i]=dist[i][0],B[i]=dist[i][1];
sort(A+1,A+n+1);sort(B+1,B+n+1);
ll res=0;
for(int i=1;i<=n;i++){
ll x=K-L-dist[i][0];
ll l=1,r=n,lb=0;
while(l<=r){
ll mid=l+r>>1;
if(B[mid]<=x){lb=mid;l=mid+1;}
else r=mid-1;
}
res+=lb;
if(dist[i][1]<=x) res--;
}
printf("%lld\n",res);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |