92522024-02-19 11:42:28TuruTamasHálózati átvitelcpp17Time limit exceeded 20/50649ms7144 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
ifstream in_file("minta/be2.txt");
#define input in_file
#define INTHENAMEOFGOD
#else
#define input cin
#define INTHENAMEOFGOD \
    ios::sync_with_stdio(0); \
    cin.tie(0); \
    cout.tie(0);
#endif
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<ll, ll> pii;

ll N, M, H, K, a, b, c;
vector<vector<pii>> G;
vi s;
vector<pii> vp;
vb in;

void dfs(ll x, ll h, ll seb) {
    in[x] = true;
    s[x] = max(s[x], seb);
    if (h == H) {
        in[x] = false;
        return;
    }
    for (pii &next : G[x]) {
        if (in[next.first]) {
            continue;
        }
        auto &p = vp[next.first];
        if (p.first <= h+1 && p.second >= min(seb, next.second)) {
            continue;
        } else if (p.first >= h+1 &&  p.second <= min(seb, next.second)) {
            p = {h+1, min(seb, next.second)};
        }
        dfs(next.first, h+1, min(seb, next.second));
    }
    in[x] = false;
}

int main() {
    INTHENAMEOFGOD
    input >> N >> M >> K >> H;
    K--;
    G.resize(N);
    s.assign(N, -1);
    vp.assign(N, {LLONG_MAX, 0});
    in.assign(N, false);
    
    for (ll m = 0; m < M; m++) {
        input >> a >> b >> c;
        a--; b--;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }

    dfs(K, 0, LLONG_MAX);
    s[K] = 0;

    for (ll val : s) {
        cout << val << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/03ms1892 KiB
2Accepted0/04ms2244 KiB
3Accepted1/13ms2304 KiB
4Accepted1/13ms2412 KiB
5Accepted2/23ms2632 KiB
6Time limit exceeded0/2600ms2756 KiB
7Accepted2/28ms3300 KiB
8Accepted2/217ms3088 KiB
9Accepted1/14ms3456 KiB
10Accepted1/1418ms3432 KiB
11Time limit exceeded0/1587ms2804 KiB
12Time limit exceeded0/1560ms2872 KiB
13Time limit exceeded0/2556ms4108 KiB
14Time limit exceeded0/2573ms3384 KiB
15Time limit exceeded0/2584ms3732 KiB
16Time limit exceeded0/2584ms3836 KiB
17Time limit exceeded0/2569ms3684 KiB
18Time limit exceeded0/2565ms3988 KiB
19Time limit exceeded0/2554ms3660 KiB
20Time limit exceeded0/2560ms4028 KiB
21Time limit exceeded0/1565ms4260 KiB
22Time limit exceeded0/1578ms4456 KiB
23Time limit exceeded0/1569ms4692 KiB
24Time limit exceeded0/1561ms4804 KiB
25Time limit exceeded0/2649ms4780 KiB
26Time limit exceeded0/2558ms4716 KiB
27Time limit exceeded0/2554ms4792 KiB
28Accepted2/254ms7032 KiB
29Accepted2/264ms7144 KiB
30Accepted2/261ms6948 KiB
31Accepted2/259ms6972 KiB
32Accepted2/265ms6944 KiB