92442024-02-19 11:15:51TuruTamasHálózati átvitelcpp17Time limit exceeded 5/50649ms4756 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;

void dfs(ll x, ll h, ll seb) {
    s[x] = max(s[x], seb);
    if (h == H) {
        return;
    }
    for (pii &next : G[x]) {
        auto &p = vp[next.first];
        if (p.first < h && 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));
    }
}

int main() {
    INTHENAMEOFGOD
    input >> N >> M >> K >> H;
    K--;
    G.resize(N);
    s.assign(N, -1);
    vp.assign(N, {LLONG_MAX, 0});
    
    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
base5/50
1Accepted0/03ms1892 KiB
2Accepted0/08ms2116 KiB
3Accepted1/13ms2332 KiB
4Accepted1/13ms2604 KiB
5Accepted2/212ms2732 KiB
6Time limit exceeded0/2600ms2652 KiB
7Time limit exceeded0/2552ms2876 KiB
8Time limit exceeded0/2556ms2916 KiB
9Accepted1/1104ms3016 KiB
10Time limit exceeded0/1563ms2112 KiB
11Time limit exceeded0/1633ms2376 KiB
12Time limit exceeded0/1644ms2716 KiB
13Time limit exceeded0/2574ms4152 KiB
14Time limit exceeded0/2558ms3116 KiB
15Time limit exceeded0/2644ms3404 KiB
16Time limit exceeded0/2573ms3400 KiB
17Time limit exceeded0/2564ms3724 KiB
18Time limit exceeded0/2552ms3672 KiB
19Time limit exceeded0/2552ms3776 KiB
20Time limit exceeded0/2560ms3444 KiB
21Time limit exceeded0/1564ms4124 KiB
22Time limit exceeded0/1552ms4412 KiB
23Time limit exceeded0/1564ms4572 KiB
24Time limit exceeded0/1637ms4660 KiB
25Time limit exceeded0/2600ms4476 KiB
26Time limit exceeded0/2564ms4628 KiB
27Time limit exceeded0/2569ms4756 KiB
28Time limit exceeded0/2573ms4672 KiB
29Time limit exceeded0/2565ms4704 KiB
30Time limit exceeded0/2552ms4724 KiB
31Time limit exceeded0/2649ms4676 KiB
32Time limit exceeded0/2574ms4748 KiB