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 ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=2e5+5;
const ll inf=2e18;
int n,m,s,t,l;
ll k;
struct duongdi
{
int u;
ll w;
bool operator < (const duongdi &o)const
{
return w>o.w;
}
};
ll d[2][maxN+1];
vector<duongdi> adj[maxN+1];
priority_queue<duongdi> pq;
vector<pll> vec1[maxN+1],vec2;
void dijkstra(int s,int type)
{
for(int i=1;i<=n;i++)
{
d[type][i]=inf;
}
d[type][s]=0;
pq.push({s,0});
while(!pq.empty())
{
duongdi tmp=pq.top();
pq.pop();
int u=tmp.u;
ll w=tmp.w;
if(d[type][u]<w)
{
continue;
}
for(auto [v,nw]:adj[u])
{
if(d[type][v]>d[type][u]+nw)
{
d[type][v]=d[type][u]+nw;
pq.push({v,d[type][v]});
}
}
}
}
int main()
{
//freopen("","r",stdin);
//freopen("","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 u,v,w;
cin>>u>>v>>w;
adj[u].push_back({v,w});
adj[v].push_back({u,w});
}
dijkstra(s,0);
dijkstra(t,1);
sort(d[0]+1,d[0]+n+1);
sort(d[1]+1,d[1]+n+1);
ll ans=0;
for(int i=1,j=n;i<=n;i++)
{
while(j>0&&d[0][i]+d[1][j]+l>k)
{
j--;
}
ans+=j;
}
cout<<ans;
}
Compilation message (stderr)
Main.cpp: In function 'void dijkstra(int, int)':
Main.cpp:43:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
43 | for(auto [v,nw]:adj[u])
| ^
# | 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... |