Submission #1245128

#TimeUsernameProblemLanguageResultExecution timeMemory
1245128tanakornsookhanonsawatConstruction Project 2 (JOI24_ho_t2)C++20
0 / 100
2096 ms141380 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, long long> pill;
typedef pair<long long, int> plli;

// void dijk(vector<pill> adj[], long long dis[], int n, int u) {
//     int processed[n + 1] = {};
//     priority_queue<plli, vector<plli>, greater<plli>> pq;
//     dis[u] = 0;
//     pq.push({dis[u], u});
//     while (!pq.empty()) {
//         int curu = pq.top().second;
//         int curdis = pq.top().first;
//         pq.pop();
//         if (!processed[curu]) {
//             processed[curu] = 1;
//             for (pill ptemp: adj[curu]) {
//                 int v = ptemp.second;
//                 int w = ptemp.first;
//                 if (!processed[v]) {
//                     dis[v] = min(dis[v], dis[curu] + w);
//                     pq.push({dis[v], v});
//                 }
//             }
//         }
//     }
    
//     cout << "\n\n";
//     cout << "dis[n + 1] :\n";
//     for (int i = 1; i <= n; i++) {
//         cout << setw(3) << i << "  =  " << dis[i] << "\n";
//     }
//     cout << "\n\n";
// }

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int i, j;
    int n, m, s, t;
    long long l, k, mxdis = 3e9, ans = 0;
    cin >> n >> m;
    cin >> s >> t >> l >> k;
    long long dis[n + 1][n + 1], adj[n + 1][n + 1];
    // long long dis[n + 1];
    // vector<pill> adj[n + 1];
    
    // for (i = 0; i <= n; i++) {
    //     dis[i] = mxdis;
    // }
    for (i = 0; i <= n; i++) {
        for (j = 0; j <= n; j++) {
            dis[i][j] = mxdis;
            adj[i][j] = mxdis;
        }
    }

    for (i = 0; i < m; i++) {
        int a, b;
        long long c;
        cin >> a >> b >> c;
        // adj[a].push_back({c, b});
        // adj[b].push_back({c, a});
        adj[a][b] = c;
        adj[b][a] = c;
    }
    // dijk(adj, dis, n, s);
    for (i = 0; i <= n; i++) {
        for (j = 0; j <= n; j++) {
            if (i == j) {
                dis[i][j] = 0;
            }
            else if (adj[i][j]) {
                dis[i][j] = adj[i][j];
            }
        }
    }
    for (int i2 = 1; i2 <= n; i2++) {
        for (i = 1; i <= n; i++) {
            for (j = 1; j <= n; j++) {
                dis[i][j] = min(dis[i][j], dis[i][i2] + dis[i2][j]);
            }
        }
    }

    ans += (l <= k);
    for (i = 1; i <= n; i++) {
        if ((i != s) && (i != t)) {
            ans += (dis[s][i] + l <= k);
            ans += (l + dis[i][t] <= k);
        }
    }
    for (i = 1; i <= n; i++) {
        for (j = 1; j <= n; j++) {
            if ((i < j) && (i != s) && (j != t)) {
                if (dis[s][i] + dis[j][t] + l <= k) {
                    ans++;
                    // cout << i << " " << j << "\n";
                }
            }
        }
    }
    
    // cout << "\n\n";
    // cout << "dis[n + 1][n + 1] :\n";
    // for (i = 1; i <= n; i++) {
    //     cout << setw(3) << i << "  =  " << dis[s][i] << "\n";
    // }
    // cout << "\n\n";
    
    // for (i = 0; i <= n; i++) {
    //     cout << dis[i] << "\n";
    // }

    cout << ans;
    
    return 0;
}

/*
7 8
6 7 1 2
1 2 1
1 6 1
2 3 1
2 4 1
3 5 1
3 7 1
4 5 1
5 6 1

3 2
1 3 1 2
1 2 1
2 3 1

18 21
4 8 678730772 3000000062
5 13 805281073
8 17 80983648
3 8 996533440
10 16 514277428
2 5 57914340
6 11 966149890
8 12 532734310
2 9 188599710
2 3 966306014
12 16 656457780
16 18 662633078
1 15 698078877
2 8 665665772
2 6 652261981
14 15 712798281
7 13 571169114
13 14 860543313
6 7 454251187
9 14 293590683
6 14 959532841
3 11 591245645
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...