153092025-02-18 09:55:47tamasmarkHálózati átvitelcpp17Accepted 50/50148ms5776 KiB
// halozat vitel 2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <deque>
#include <queue>
#include <algorithm>
using namespace std;
struct adat
{
    int ertek;
    int tav;
    int index;
};
bool operator<(const adat& a, const adat& b)
{
    if (a.ertek == b.ertek)
    {
        return (a.tav < b.tav);
    }
    else return(a.ertek > b.ertek);
}

int main()
{
    int n, m, i, j, k, h;
    cin >> n >> m >> k >> h;
    vector<vector<pair<int,int>>>x(n + 1);
    for (int i = 1; i <= m; ++i)
    {
        int a, b,c;
        cin >> a >> b>>c;
        x[a].push_back({ b,c });
        x[b].push_back({ a,c });
    }
    queue<adat>q;
    q.push({ 0,0,k });
    vector<vector<int>>dp(n + 1, vector<int>(h + 1,0));
    while (!q.empty())
    {
        adat akt=q.front();
        q.pop();
        if (akt.tav >= h || dp[akt.index][akt.tav] > akt.ertek)
        {
            continue;
        }
        for (int i = 0; i < x[akt.index].size(); ++i)
        {
            adat uj;
            if (akt.ertek == 0)
            {
                uj.ertek= x[akt.index][i].second;
            }
            else
            {
                uj.ertek = min(x[akt.index][i].second, akt.ertek);
            }

            adat csp = { uj.ertek,akt.tav + 1,x[akt.index][i].first };
            if (csp.ertek > dp[csp.index][csp.tav])
            {
                dp[csp.index][csp.tav] = csp.ertek;
                q.push(csp);
            }
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        if (i == k)
        {
            cout << 0 << "\n";
            continue;
        }
        int maxi=0;
        for (int j = 0; j <=h; ++j)
            maxi = max(maxi, dp[i][j]);
        if (maxi != 0)
            cout << maxi << "\n";
        else cout << -1 << "\n";
    }
    return 0;
}
/*
5 6 1 2
1 2 2
1 5 4
1 3 2
1 4 3
5 4 1
5 3 4

*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/01ms500 KiB
3Accepted1/11ms316 KiB
4Accepted1/11ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/22ms376 KiB
8Accepted2/22ms316 KiB
9Accepted1/12ms564 KiB
10Accepted1/14ms564 KiB
11Accepted1/17ms516 KiB
12Accepted1/18ms564 KiB
13Accepted2/27ms564 KiB
14Accepted2/28ms740 KiB
15Accepted2/217ms956 KiB
16Accepted2/214ms864 KiB
17Accepted2/216ms924 KiB
18Accepted2/220ms988 KiB
19Accepted2/217ms824 KiB
20Accepted2/216ms920 KiB
21Accepted1/150ms4684 KiB
22Accepted1/174ms4776 KiB
23Accepted1/189ms4760 KiB
24Accepted1/1107ms4852 KiB
25Accepted2/2138ms5684 KiB
26Accepted2/2135ms5712 KiB
27Accepted2/2148ms5776 KiB
28Accepted2/254ms5120 KiB
29Accepted2/261ms5684 KiB
30Accepted2/259ms5684 KiB
31Accepted2/257ms5684 KiB
32Accepted2/263ms5684 KiB