Submission #1315513

#TimeUsernameProblemLanguageResultExecution timeMemory
1315513samarthkulkarniConstruction Project 2 (JOI24_ho_t2)C++20
0 / 100
1 ms332 KiB
// joi final round 2024
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define vi vector<long long>
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pr pair<ll, ll>
#define ff first
#define ss second

void solution();
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solution();
    return 0;
}


const int N = 2e5+10;
vector<pr> adj[N];
ll n, m;

void dij(int a, vi &dist) {
	dist.resize(n+1, 5e18);
	vector<bool> vis(n+1);

	priority_queue<pr> q;
	dist[a] = 0;
	q.push({0, a});

	while (!q.empty()) {
		auto [d, u] = q.top(); q.pop();
		if (vis[u]) continue;
		vis[u] = true;

		for (auto [v, w] : adj[u]) {
			if (dist[u] + w < dist[v]) {
				dist[v] = dist[u] + w;
				q.push({-dist[v], v});
			}
		}
	}
}


void solution() {
	cin >> n >> m;
	ll S, T, l, k;
	cin >> S >> T >> l >> k;

	while (m--) {
		ll a, b, w;
		cin >> a >> b >> w;
		adj[a].push_back({b, w});
		adj[b].push_back({a, w});
	}


	vi d1, d2;
	dij(S, d1);
	dij(T, d2);


	ll ans = 0;

	set<pr> pre;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {

			int t1 = i, t2 = j;
			if (t1 > t2) swap(t1, t2);
			if (pre.count({t1, t2})) continue;
			if (j == i) continue;

			if (d1[i] + d2[j] + l <= k) { 
				ans++;
				pre.insert({t1, t2});
			}
		}
	}
	cout << ans << endl;


}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...