92352024-02-19 10:42:06TuruTamasHálózati átvitelcpp17Runtime error 2/5068ms64836 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;

struct P {
    ll ind, seb, tav;
};

void bfs() {
    queue<P> q;
    q.push((P) {
        .ind = K,
        .seb = LLONG_MAX,
        .tav = 0,
    });
    while (!q.empty()) {
        P c = move(q.front());
        q.pop();
        if (c.tav == H) {
            continue;
        }
        // cout << "asd" << "\n";
        for (pii &next : G[c.ind]) {
            s[next.first] = max(s[next.first], min(c.seb, next.second));
            q.push((P) {
                .ind = next.first,
                .seb = min(c.seb, next.second),
                .tav = c.tav+1
            });
        }
    }
    
}

int main() {
    INTHENAMEOFGOD
    input >> N >> M >> K >> H;
    K--;
    G.resize(N);
    s.assign(N, -1);
    
    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);
    }

    bfs();
    s[K] = 0;

    for (ll val : s) {
        cout << val << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base2/50
1Accepted0/03ms1828 KiB
2Runtime error0/046ms64836 KiB
3Accepted1/13ms2388 KiB
4Accepted1/13ms2976 KiB
5Runtime error0/254ms64176 KiB
6Runtime error0/246ms63940 KiB
7Runtime error0/252ms63696 KiB
8Runtime error0/246ms63688 KiB
9Runtime error0/159ms63656 KiB
10Runtime error0/157ms63656 KiB
11Runtime error0/154ms63632 KiB
12Runtime error0/154ms63520 KiB
13Runtime error0/254ms63516 KiB
14Runtime error0/254ms63284 KiB
15Runtime error0/254ms63184 KiB
16Runtime error0/250ms63196 KiB
17Runtime error0/254ms63028 KiB
18Runtime error0/254ms62964 KiB
19Runtime error0/250ms62972 KiB
20Runtime error0/250ms62960 KiB
21Runtime error0/159ms62956 KiB
22Runtime error0/165ms62956 KiB
23Runtime error0/167ms62936 KiB
24Runtime error0/165ms62932 KiB
25Runtime error0/267ms62956 KiB
26Runtime error0/268ms62956 KiB
27Runtime error0/268ms62956 KiB
28Runtime error0/250ms62812 KiB
29Runtime error0/252ms62812 KiB
30Runtime error0/252ms62812 KiB
31Runtime error0/252ms62816 KiB
32Runtime error0/252ms62816 KiB