#include <bitset>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#define pb push_back
#define MOD 1000000007
#define NMAX 200001
#define nl '\n'
#define INF 1000000007
#define pii1 pair<int, pair<int,int>> (1,(1,2));
#define pii pair<int,int>
#define tpl tuple<int,int,int,int,int>
using namespace std;
ifstream fin("data.in");
ofstream fout("data.out");
/*
====================DEMONSTRATION======================
=========================END===========================
*/
int n,m,s,t,l,k;
vector<int>v;
vector<vector<pii>>G(NMAX);
vector<int>dist_s,dist_t;
priority_queue<pii,vector<pii>,greater<pii>>pq;
void dijkstra(int node,vector<int>&dist)
{
for(int i=0;i<n;++i)
dist[i]=INF;
dist[node]=0;
pq.push({0,node});
while(!pq.empty())
{
auto [dis,first]=pq.top();
pq.pop();
if(dist[first]<dis)
continue;
for(auto [u,w]:G[first])
{
if(dist[u]>dist[first]+w)
{
dist[u]=dist[first]+w;
pq.push({dist[u],u});
}
}
}
}
signed main() {
cin>>n>>m;
cin>>s>>t>>l>>k;
s--;
t--;
dist_s.resize(n,INF);
dist_t.resize(n,INF);
for(int i=1;i<=m;++i)
{
int x,y,c;
cin>>x>>y>>c;
x--;
y--;
G[x].pb({y,c});
G[y].pb({x,c});
}
dijkstra(s,dist_s);
dijkstra(t,dist_t);
if(dist_s[t]<=k)
{
cout<<(n*(n-1)/2);
return 0;
}
sort(dist_t.begin(),dist_t.end());
int ans=0;
for(int i=0;i<n;++i)
{
int dis=k-l-dist_s[i];
int pos= lower_bound(dist_t.begin(),dist_t.end(),dis+1)-dist_t.begin();
ans+=pos;
}
cout<<ans;
return 0;
}
Compilation message
Main.cpp: In function 'void dijkstra(int, std::vector<int>&)':
Main.cpp:56:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
56 | auto [dis,first]=pq.top();
| ^
Main.cpp:60:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
60 | for(auto [u,w]:G[first])
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5212 KB |
Output is correct |
7 |
Correct |
92 ms |
14432 KB |
Output is correct |
8 |
Correct |
139 ms |
16800 KB |
Output is correct |
9 |
Incorrect |
119 ms |
16696 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4952 KB |
Output is correct |
4 |
Runtime error |
9 ms |
10040 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4952 KB |
Output is correct |
4 |
Runtime error |
9 ms |
10040 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5212 KB |
Output is correct |
7 |
Correct |
92 ms |
14432 KB |
Output is correct |
8 |
Correct |
139 ms |
16800 KB |
Output is correct |
9 |
Incorrect |
119 ms |
16696 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |