32772023-02-23 17:06:521478Hálózati átvitelcpp17Wrong answer 0/5027ms15724 KiB
#include <bits/stdc++.h>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

int main()
{
    fast_cin();
    //ifstream cin("in.txt");

    int n;
    cin >> n;
    int m;
    cin >> m;
    int k;
    cin >> k;
    int h;
    cin >> h;

    vector<vector<pair<int, int>>> aL(n + 1);

    for (int i = 1; i <= m; i++)
    {
        int a;
        cin >> a;
        int b;
        cin >> b;
        int c;
        cin >> c;

        aL[a].push_back({b, c});
        aL[b].push_back({a, c});
    }

    priority_queue<pair<int, pair<int, int>>> pq;

    vector<vector<int>> ans(n + 1, vector<int>(h + 1));
    for (int i = 0; i < aL[k].size(); i++)
    {
        pq.push({aL[k][i].second, {k, aL[k][i].first}});
    }
    vector<bool> check(n + 1);
    check[k] = 1;

    while (!pq.empty())
    {

        int a = pq.top().second.first;
        int b = pq.top().second.second;
        int c = pq.top().first;

        // cout << a << " " << b << " " << c << '\n';
        pq.pop();
        check[b] = 1;

        if (a == k)
        {
            ans[b][1] = c;
        }
        else
        {
            for (int i = 1; i <= h; i++)
            {
                ans[b][i] = max(ans[b][i], min(ans[a][i - 1], c));
            }
        }

        /*for (int j = 0; j <= h; j++)
        {
            cout << ans[b][j] << " ";
        }
        cout << '\n';
        cout << '\n';*/

        for (int i = 0; i < aL[b].size(); i++)
        {
            if (!check[aL[b][i].first])
            {
                pq.push({aL[b][i].second, {b, aL[b][i].first}});
            }
        }
    }

    for (int i = 1; i <= n; i++)
    {
        int anss = -1;
        for (int j = 0; j <= h; j++)
        {
            anss = max(anss, ans[i][j]);
        }
        cout << anss << '\n';
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/03ms1920 KiB
2Wrong answer0/03ms2104 KiB
3Wrong answer0/13ms2248 KiB
4Wrong answer0/13ms2460 KiB
5Wrong answer0/23ms2824 KiB
6Wrong answer0/23ms3040 KiB
7Wrong answer0/23ms3284 KiB
8Wrong answer0/23ms3236 KiB
9Wrong answer0/13ms3656 KiB
10Wrong answer0/14ms3940 KiB
11Wrong answer0/14ms4292 KiB
12Wrong answer0/17ms4220 KiB
13Wrong answer0/24ms4308 KiB
14Wrong answer0/26ms4652 KiB
15Wrong answer0/29ms5668 KiB
16Wrong answer0/29ms5480 KiB
17Wrong answer0/29ms5808 KiB
18Wrong answer0/210ms6100 KiB
19Wrong answer0/29ms6212 KiB
20Wrong answer0/29ms6124 KiB
21Wrong answer0/114ms13152 KiB
22Wrong answer0/117ms13360 KiB
23Wrong answer0/120ms13284 KiB
24Wrong answer0/123ms13800 KiB
25Wrong answer0/225ms15476 KiB
26Wrong answer0/224ms15360 KiB
27Wrong answer0/227ms15692 KiB
28Wrong answer0/217ms14260 KiB
29Wrong answer0/218ms15620 KiB
30Wrong answer0/218ms15724 KiB
31Wrong answer0/218ms15552 KiB
32Wrong answer0/218ms15584 KiB