92342024-02-19 10:36:16TuruTamasHálózati átvitelcpp17Runtime error 2/5063ms64852 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 = 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/048ms64852 KiB
3Accepted1/13ms2376 KiB
4Accepted1/13ms2960 KiB
5Runtime error0/250ms64400 KiB
6Runtime error0/246ms64164 KiB
7Runtime error0/246ms63992 KiB
8Runtime error0/246ms63992 KiB
9Runtime error0/159ms63756 KiB
10Runtime error0/157ms63496 KiB
11Runtime error0/150ms63260 KiB
12Runtime error0/148ms63096 KiB
13Runtime error0/248ms63068 KiB
14Runtime error0/246ms63076 KiB
15Runtime error0/246ms63072 KiB
16Runtime error0/248ms63056 KiB
17Runtime error0/254ms62900 KiB
18Runtime error0/248ms62888 KiB
19Runtime error0/248ms62664 KiB
20Runtime error0/248ms62660 KiB
21Runtime error0/159ms62628 KiB
22Runtime error0/159ms62624 KiB
23Runtime error0/161ms62612 KiB
24Runtime error0/159ms62644 KiB
25Runtime error0/257ms62644 KiB
26Runtime error0/261ms62644 KiB
27Runtime error0/263ms62644 KiB
28Runtime error0/246ms62644 KiB
29Runtime error0/246ms62628 KiB
30Runtime error0/246ms62612 KiB
31Runtime error0/246ms62628 KiB
32Runtime error0/246ms62620 KiB