92472024-02-19 11:17:14TuruTamasHálózati átvitelcpp17Time limit exceeded 7/50649ms5276 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+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));
    }
}

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
base7/50
1Accepted0/03ms2040 KiB
2Accepted0/04ms2348 KiB
3Accepted1/13ms2516 KiB
4Accepted1/13ms2552 KiB
5Accepted2/26ms2648 KiB
6Time limit exceeded0/2559ms2676 KiB
7Accepted2/257ms2692 KiB
8Time limit exceeded0/2563ms2892 KiB
9Accepted1/1104ms3012 KiB
10Time limit exceeded0/1570ms3016 KiB
11Time limit exceeded0/1558ms2432 KiB
12Time limit exceeded0/1564ms2452 KiB
13Time limit exceeded0/2566ms2524 KiB
14Time limit exceeded0/2558ms2804 KiB
15Time limit exceeded0/2574ms3028 KiB
16Time limit exceeded0/2574ms3100 KiB
17Time limit exceeded0/2580ms3012 KiB
18Time limit exceeded0/2560ms3328 KiB
19Time limit exceeded0/2577ms3600 KiB
20Time limit exceeded0/2580ms3580 KiB
21Time limit exceeded0/1577ms3896 KiB
22Time limit exceeded0/1556ms4176 KiB
23Time limit exceeded0/1555ms4660 KiB
24Time limit exceeded0/1574ms4816 KiB
25Time limit exceeded0/2643ms4876 KiB
26Time limit exceeded0/2561ms4800 KiB
27Time limit exceeded0/2574ms4948 KiB
28Time limit exceeded0/2649ms5096 KiB
29Time limit exceeded0/2570ms5204 KiB
30Time limit exceeded0/2565ms5240 KiB
31Time limit exceeded0/2570ms5276 KiB
32Time limit exceeded0/2565ms5224 KiB