95692024-02-23 10:33:22zsebiHálózati átvitelcpp17Wrong answer 0/5028ms7800 KiB
// halozati.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>

#define ll long long 
using namespace std;
ll n, m, kezd, maxim;
struct adat
{
    ll lep = 0, lat = 0, ert = -1;
    vector<pair<ll, ll>>sz;
};
vector<adat>x;
struct ut
{
    ll  hova,mini;
};
priority_queue<ut>v;
bool operator<(const ut& a, const ut& b)
{
    return a.mini < b.mini;
}

int main()
{
    cin >> n >> m >> kezd >> maxim;
    x.resize(n + 1);
    for (int i = 1; i <= m; ++i)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        x[a].sz.push_back({ b,c });
        x[b].sz.push_back({ a,c });
    }

    v.push({ kezd,100001 });
    while (!v.empty())
    {
        ut akt = v.top();
        while (x[akt.hova].lat && !v.empty())
        {
            akt = v.top();
            v.pop();
        }
        if (v.empty())break;
        x[akt.hova].lat = 1;
        x[akt.hova].ert = akt.mini;
        for (auto& e : x[akt.hova].sz)
        {
            if (!x[e.first].lat && x[akt.hova].lep + 1 <= maxim)
            {
                ll a = min(x[akt.hova].ert, e.second);
                if (a > x[e.first].ert)
                {
                    x[e.first].lep = x[akt.hova].lep + 1;
                    x[e.first].ert = min(x[akt.hova].ert, e.second);
                    v.push({ e.first,x[e.first].ert });
                }
            }
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        if (i == kezd)cout << "0\n";
        else cout << x[i].ert << "\n";
    }
    return 0;
}

// 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
base0/50
1Accepted0/03ms1880 KiB
2Wrong answer0/03ms2156 KiB
3Wrong answer0/13ms2216 KiB
4Wrong answer0/13ms2496 KiB
5Wrong answer0/23ms2668 KiB
6Wrong answer0/23ms2808 KiB
7Wrong answer0/24ms3056 KiB
8Wrong answer0/23ms3012 KiB
9Wrong answer0/14ms3296 KiB
10Wrong answer0/14ms3568 KiB
11Wrong answer0/16ms3752 KiB
12Wrong answer0/18ms3908 KiB
13Wrong answer0/26ms3952 KiB
14Wrong answer0/28ms4128 KiB
15Wrong answer0/212ms5036 KiB
16Wrong answer0/212ms5012 KiB
17Wrong answer0/212ms5268 KiB
18Wrong answer0/212ms5344 KiB
19Wrong answer0/212ms5368 KiB
20Wrong answer0/212ms5608 KiB
21Wrong answer0/114ms6244 KiB
22Wrong answer0/117ms6256 KiB
23Wrong answer0/119ms6656 KiB
24Wrong answer0/125ms7292 KiB
25Wrong answer0/227ms7568 KiB
26Wrong answer0/227ms7696 KiB
27Wrong answer0/228ms7800 KiB
28Wrong answer0/225ms7684 KiB
29Wrong answer0/225ms7784 KiB
30Wrong answer0/225ms7556 KiB
31Wrong answer0/224ms7568 KiB
32Wrong answer0/225ms7696 KiB