제출 #1329639

#제출 시각아이디문제언어결과실행 시간메모리
1329639chikien2009Construction Project 2 (JOI24_ho_t2)C++20
0 / 100
3 ms3396 KiB
#include <bits/stdc++.h>

using namespace std;

void setup()
{
// #ifndef ONLINE_JUDGE
//     freopen("test.inp", "r", stdin);
//     freopen("test.out", "w", stdout);
// #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int n, m, a, b, c, s, t, l;
long long res, k;
long long dist_from_s[200000], dist_from_t[200000];
vector<pair<int, int>> g[200000];
priority_queue<pair<long long, int>> pq;

inline void Dijkstra(int node, long long (&dist)[200000])
{
    long long cost;
    fill_n(dist, 2e5, 1e18);
    dist[node] = 0;
    pq.push({0, node});
    cout << node << "\n";
    cout << g[node].size() << "\n";
    while (!pq.empty())
    {
        node = pq.top().second;
        cost = -pq.top().first;
        pq.pop();
        if (dist[node] != cost)
        {
            continue;
        }
        for (auto &i : g[node])
        {
            if (dist[i.first] > cost + i.second)
            {
                dist[i.first] = cost + i.second;
                pq.push({-dist[i.first], i.first});
            }
        }
    }
}

int main()
{
    setup();

    cin >> n >> m >> s >> t >> l >> k;
    while (m--)
    {
        cin >> a >> b >> c;
        g[a - 1].push_back({b - 1, c});
        g[b - 1].push_back({a - 1, c});
    }
    Dijkstra(s - 1, dist_from_s);
    Dijkstra(t - 1, dist_from_t);
    if (dist_from_s[t - 1] <= k)
    {
        cout << (long long)n * (n - 1) / 2;
        return 0;
    }
    sort(dist_from_s, dist_from_s + n);
    sort(dist_from_t, dist_from_t + n);
    for (int i = 0; i < n; ++i)
    {
        res += upper_bound(dist_from_t, dist_from_t + n, k - l - dist_from_s[i]) - dist_from_t;
    }
    cout << res;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...