239872026-02-03 08:30:28szabelrHálózati átvitelcpp17Accepted 50/5037ms1524 KiB
// Hálózati átvitel.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <queue>
#include <climits>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, k, h;
    cin >> n >> m >> k >> h;
    vector<vector<pair<int,int>>> adj(n + 1);
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back({ b,c });
        adj[b].push_back({ a,c });
    }
    vector<int> mini(n + 1, -1);
    mini[k] = 0;
    queue<pair<int, pair<int, int>>> q;
    q.push({ 0,{k,INT_MAX} });
    while (!q.empty())
    {
        auto it = q.front();
        q.pop();
        int stops = it.first;
        int node = it.second.first;
        int speed = it.second.second;
        if (stops >= h) continue;
        for (auto iterator : adj[node])
        {
            int adjNode = iterator.first;
            int curSpeed = iterator.second;
            if (min(speed, curSpeed) > mini[adjNode])
            {
                mini[adjNode] = min(speed, curSpeed);
                q.push({ stops + 1,{adjNode,mini[adjNode]} });
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (i != k)
            cout << mini[i] << endl;
        else
            cout << 0 << endl;
    }
       

}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted1/11ms316 KiB
4Accepted1/11ms508 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted1/13ms316 KiB
10Accepted1/14ms316 KiB
11Accepted1/14ms564 KiB
12Accepted1/14ms756 KiB
13Accepted2/24ms520 KiB
14Accepted2/24ms480 KiB
15Accepted2/27ms524 KiB
16Accepted2/27ms564 KiB
17Accepted2/28ms564 KiB
18Accepted2/28ms760 KiB
19Accepted2/27ms564 KiB
20Accepted2/27ms756 KiB
21Accepted1/120ms1080 KiB
22Accepted1/127ms1076 KiB
23Accepted1/128ms1524 KiB
24Accepted1/130ms1332 KiB
25Accepted2/232ms1332 KiB
26Accepted2/235ms1460 KiB
27Accepted2/235ms1504 KiB
28Accepted2/235ms1524 KiB
29Accepted2/237ms1332 KiB
30Accepted2/237ms1332 KiB
31Accepted2/237ms1388 KiB
32Accepted2/237ms1424 KiB