42752023-03-21 11:24:49tamasmarkHálózati átvitelcpp17Wrong answer 3/5028ms9244 KiB
// halozatatvitel.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <climits>
#define ll long long

using namespace std;
struct ut
{
    ll hova, hossz,lep;
};
struct adat
{
    bool lat;
    ll 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;
}
ll n, i, a, b, c, db,m,k,h;

int main()
{
    cin >> n >> m>>k>>h;
    vector<adat>x(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,0 });
    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;
        x[akt.hova].lep = akt.lep;
        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 + 1 <= h)
            {
                x[e.hova].tav = min(akt.hossz, e.hossz);
                if(!x[e.hova].lep)x[e.hova].lep =akt.lep+1;
                que.push({ e.hova,min(akt.hossz , e.hossz),x[e.hova].lep});
            }
            else if (akt.lep + 1 > h&&!x[e.hova].lat) x[e.hova].tav = -1;
        }
    }
    x[k].tav = 0;
    for (i = 1; i <= n; ++i) cout << x[i].tav << "\n";
    return 0;
}
/*
7 8 1 2
1 2 2
1 5 4
1 3 2
1 4 3
5 4 1
5 3 4
5 6 1
6 7 8

*/
// 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
base3/50
1Accepted0/03ms1960 KiB
2Wrong answer0/03ms2348 KiB
3Wrong answer0/13ms2336 KiB
4Wrong answer0/13ms2468 KiB
5Wrong answer0/23ms2576 KiB
6Wrong answer0/23ms2936 KiB
7Wrong answer0/24ms3220 KiB
8Wrong answer0/23ms3164 KiB
9Wrong answer0/14ms3204 KiB
10Wrong answer0/14ms3476 KiB
11Accepted1/16ms4056 KiB
12Wrong answer0/18ms4332 KiB
13Wrong answer0/26ms4072 KiB
14Wrong answer0/28ms4320 KiB
15Wrong answer0/212ms5268 KiB
16Wrong answer0/213ms5568 KiB
17Wrong answer0/212ms5668 KiB
18Wrong answer0/212ms5608 KiB
19Wrong answer0/213ms5620 KiB
20Wrong answer0/212ms5760 KiB
21Wrong answer0/114ms5784 KiB
22Wrong answer0/119ms6696 KiB
23Wrong answer0/123ms7560 KiB
24Wrong answer0/126ms7920 KiB
25Wrong answer0/227ms8224 KiB
26Wrong answer0/227ms8236 KiB
27Accepted2/228ms8880 KiB
28Wrong answer0/226ms8904 KiB
29Wrong answer0/225ms8984 KiB
30Wrong answer0/225ms8932 KiB
31Wrong answer0/224ms8972 KiB
32Wrong answer0/226ms9244 KiB