Submission #1262194

#TimeUsernameProblemLanguageResultExecution timeMemory
1262194tuanmwillwinvoi26Construction Project 2 (JOI24_ho_t2)C++20
0 / 100
25 ms8264 KiB
#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 = 3e3 + 5;

int n , m;
int s , t , l , k;
vector <pair<int , int>> adj[MAXN];
int dist_s[MAXN] , dist_t[MAXN];
int res;
priority_queue <pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>>> pq;
bool ap[MAXN][MAXN];

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".ans" , "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 ++){
        for(int j = 1 ; j <= n ; j ++){
            if (i == j) continue;
            if (ap[i][j] == 1 || ap[j][i] == 1) continue;
            if (dist_s[i] + l + dist_t[j] <= k){
                res ++;
                ap[i][j] = ap[j][i] = 1;
            }
        }
    }

    cout << res;

    return 0;
}

/*
⠀⠀⠀⠀⠀⠀⢀⡤⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡀
⠀⠀⠀⠀⠀⢀⡏⠀⠀⠈⠳⣄⠀⠀⠀⠀⠀⣀⠴⠋⠉⠉⡆
⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠈⠉⠉⠙⠓⠚⠁⠀⠀⠀⠀⣿
⠀⠀⠀⠀⢀⠞⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣄
⠀⠀⠀⠀⡞⠀⠀⠀⠀⠀⠶⠀⠀⠀⠀⠀⠀⠦⠀⠀⠀⠀⠀⠸⡆


                                    */

Compilation message (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".ans" , "w" , stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...