#include <bits/stdc++.h>
using namespace std;
#define el '\n'
#define TASK "metro"
#define int long long
const int INF = 1e18 + 829;
const int MAXN = 2e5 + 5;
int n , m;
int s , t , l , k;
vector <pair<int , int>> adj[MAXN];
int dist_s[MAXN] , dist_t[MAXN];
int res;
vector <int> v;
priority_queue <pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>>> pq;
void dijkstra(int node , int dist[]){
for(int i = 1 ; i <= n ; i ++){
dist[i] = INF;
}
dist[node] = 0;
pq.push({0 , node});
while(! pq.empty()){
int cost = pq.top().first;
int u = pq.top().second;
pq.pop();
if (cost != dist[u]) continue;
for(auto x : adj[u]){
int v = x.first;
int w = x.second;
if (dist[v] > dist[u] + w){
dist[v] = dist[u] + w;
pq.push({dist[v] , v});
}
}
}
}
signed main(){
if (fopen(TASK".inp" , "r")){
freopen(TASK".inp" , "r" , stdin);
freopen (TASK".out" , "w" , stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
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 , dist_s);
dijkstra(t , dist_t);
for(int i = 1 ; i <= n ; i ++){
v.push_back(dist_t[i]);
}
sort(v.begin() , v.end());
for(int i = 1 ; i <= n ; i ++){
if (dist_s[i] == INF) continue;
int wanted = k - l - dist_s[i];
if (wanted < 0) continue;
int pos = upper_bound(v.begin() , v.end() , wanted) - v.begin();
res += pos;
}
cout << res;
return 0;
}
/*
⠀⠀⠀⠀⠀⠀⢀⡤⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡀
⠀⠀⠀⠀⠀⢀⡏⠀⠀⠈⠳⣄⠀⠀⠀⠀⠀⣀⠴⠋⠉⠉⡆
⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠈⠉⠉⠙⠓⠚⠁⠀⠀⠀⠀⣿
⠀⠀⠀⠀⢀⠞⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣄
⠀⠀⠀⠀⡞⠀⠀⠀⠀⠀⠶⠀⠀⠀⠀⠀⠀⠦⠀⠀⠀⠀⠀⠸⡆
*/
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | freopen(TASK".inp" , "r" , stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:48:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | freopen (TASK".out" , "w" , stdout);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |