34182023-02-27 13:43:00Error42Hálózati átvitelcpp17Accepted 50/5032ms6492 KiB
// code of `kdb`, only debugged by `Error-42` 

#include <iostream>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;

std::ostream& operator<<(std::ostream& os, const std::vector<int>& input)
{
    for (auto const& i : input) {
        os << i << "\n";
    }
    return os;
}

int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n, m, k, h;
    cin >> n >> m >> k >> h;
    vector<int>ki(n + 1, -1);
    vector<int>ki2(n + 1, -1);
    vector<vector<pair<int, int>>>vec(n + 1);

    for (size_t i = 0; i < m; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        vec[u].push_back({ v,w });
        vec[v].push_back({ u,w });
    }

    ki[k] = INT_MAX;
    ki2[k] = INT_MAX;

    for (size_t i = 0; i < h; i++)
    {
        for (size_t j = 1; j < n + 1; j++)
        {
            for (auto q : vec[j])
            {
                if (ki[q.first] < min(q.second, ki2[j]))
                {
                    ki[q.first] = min(q.second, ki2[j]);
                }
            }
        }
        ki2 = ki;
    }
    ki[k] = 0;
    for (size_t i = 1; i < n + 1; i++)
    {
        cout << ki[i] << "\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
*/
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2104 KiB
2Accepted0/03ms2244 KiB
3Accepted1/13ms2364 KiB
4Accepted1/13ms2572 KiB
5Accepted2/23ms2848 KiB
6Accepted2/23ms2884 KiB
7Accepted2/23ms3120 KiB
8Accepted2/23ms2980 KiB
9Accepted1/13ms3264 KiB
10Accepted1/14ms3488 KiB
11Accepted1/14ms3936 KiB
12Accepted1/14ms4096 KiB
13Accepted2/24ms4220 KiB
14Accepted2/24ms4228 KiB
15Accepted2/28ms4468 KiB
16Accepted2/27ms4468 KiB
17Accepted2/28ms4420 KiB
18Accepted2/28ms4416 KiB
19Accepted2/28ms4548 KiB
20Accepted2/28ms4808 KiB
21Accepted1/117ms5392 KiB
22Accepted1/120ms5520 KiB
23Accepted1/123ms5680 KiB
24Accepted1/126ms6044 KiB
25Accepted2/230ms6016 KiB
26Accepted2/230ms5920 KiB
27Accepted2/232ms6272 KiB
28Accepted2/217ms6260 KiB
29Accepted2/218ms6404 KiB
30Accepted2/217ms6460 KiB
31Accepted2/217ms6492 KiB
32Accepted2/217ms6460 KiB