42722023-03-21 09:49:56tamasmarkHálózati átvitelcpp17Wrong answer 3/5028ms8060 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;
};
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 });
    while (!que.empty())
    {
        akt = que.top();
        while (!que.empty() && x[akt.hova].lat)
        {
            que.pop();
            if (!que.empty()) akt = que.top();
        }
        //que.pop();
        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 + 1 <= h)
            {
                x[e.hova].tav = min(akt.hossz, e.hossz);
                if(!x[e.hova].lep)x[e.hova].lep = x[akt.hova].lep + 1;
                que.push({ e.hova,min(akt.hossz , e.hossz) });
            }
            else if (x[akt.hova].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/03ms1808 KiB
2Wrong answer0/03ms2092 KiB
3Wrong answer0/13ms2288 KiB
4Wrong answer0/13ms2368 KiB
5Wrong answer0/23ms2468 KiB
6Wrong answer0/23ms2696 KiB
7Wrong answer0/23ms2968 KiB
8Wrong answer0/24ms3172 KiB
9Wrong answer0/14ms3244 KiB
10Wrong answer0/14ms3424 KiB
11Accepted1/16ms3684 KiB
12Wrong answer0/18ms4024 KiB
13Wrong answer0/26ms4152 KiB
14Wrong answer0/28ms4320 KiB
15Wrong answer0/212ms5036 KiB
16Wrong answer0/212ms5392 KiB
17Wrong answer0/212ms5728 KiB
18Wrong answer0/212ms5672 KiB
19Wrong answer0/212ms5824 KiB
20Wrong answer0/212ms5860 KiB
21Wrong answer0/114ms6184 KiB
22Wrong answer0/118ms6744 KiB
23Wrong answer0/123ms7504 KiB
24Wrong answer0/125ms7308 KiB
25Wrong answer0/227ms7732 KiB
26Wrong answer0/226ms7696 KiB
27Accepted2/228ms8060 KiB
28Wrong answer0/225ms7936 KiB
29Wrong answer0/225ms8020 KiB
30Wrong answer0/224ms7928 KiB
31Wrong answer0/224ms7940 KiB
32Wrong answer0/225ms7960 KiB