40092023-03-08 11:44:41tamasmarkHálózati átvitelcpp17Wrong answer 0/5030ms7668 KiB
// halozati atvitel.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <queue>
#include <climits>
#include <algorithm>

using namespace std;

struct ut
{
    long long hova, hossz;
};

struct adat
{
    bool lat;
    long long tav=LLONG_MIN,lep;
    vector<ut>sz;
};
priority_queue<ut>que;
ut akt;
bool operator<(const ut a, const ut b)
{
    return a.hossz < b.hossz;
}
int n, m, i, a, b, c, h, k;
vector<adat>x;
int main()
{
    cin >> n >> m >> k >> h;
    x.resize(n + 1);
    for (i = 1; i <= m; ++i)
    {
        cin >> a >> b >> c;
        x[a].sz.push_back({ b,c });
        x[b].sz.push_back({ a,c });
    }
    que.push({ k,LLONG_MAX });
    //x[k].lat = true;
    while (!que.empty())
    {
        akt = que.top();
        while (!que.empty() && x[akt.hova].lat)
        {
            que.pop();
            if (!que.empty()) akt = que.top();
        }
        if (que.empty()) break;
        x[akt.hova].lat = true;
        x[akt.hova].tav = akt.hossz;
        for (auto& e : x[akt.hova].sz)
        {
            if (!x[e.hova].lat && x[e.hova].tav < min(akt.hossz , e.hossz)&&x[akt.hova].lep<=h)
            {
                x[e.hova].tav = min(akt.hossz , e.hossz);
                x[e.hova].lep = x[akt.hova].lep + 1;
                que.push({ e.hova, min(e.hossz , akt.hossz) });
            }
        }
    }
    x[k].tav = 0;
    for (i = 1; i <= n; ++i)
    {
        if (x[i].tav != LLONG_MIN)cout << x[i].tav << "\n";
        else cout << -1;
    }
    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
base0/50
1Accepted0/03ms1932 KiB
2Wrong answer0/03ms2136 KiB
3Wrong answer0/13ms2324 KiB
4Wrong answer0/13ms2536 KiB
5Wrong answer0/23ms2764 KiB
6Wrong answer0/23ms2868 KiB
7Wrong answer0/24ms3044 KiB
8Wrong answer0/24ms3312 KiB
9Wrong answer0/14ms3296 KiB
10Wrong answer0/14ms3636 KiB
11Wrong answer0/17ms4096 KiB
12Wrong answer0/18ms4100 KiB
13Wrong answer0/26ms3960 KiB
14Wrong answer0/28ms4316 KiB
15Wrong answer0/212ms4996 KiB
16Wrong answer0/212ms4976 KiB
17Wrong answer0/212ms4964 KiB
18Wrong answer0/212ms4876 KiB
19Wrong answer0/212ms4884 KiB
20Wrong answer0/212ms4872 KiB
21Wrong answer0/114ms5176 KiB
22Wrong answer0/118ms5708 KiB
23Wrong answer0/121ms6572 KiB
24Wrong answer0/125ms6620 KiB
25Wrong answer0/227ms7308 KiB
26Wrong answer0/226ms6908 KiB
27Wrong answer0/230ms7400 KiB
28Wrong answer0/225ms7184 KiB
29Wrong answer0/225ms7324 KiB
30Wrong answer0/224ms7424 KiB
31Wrong answer0/225ms7604 KiB
32Wrong answer0/225ms7668 KiB