92572024-02-19 11:49:52TuruTamasHálózati átvitelcpp17Time limit exceeded 15/50651ms7104 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;
vb in;

void dfs(ll x, ll h, ll seb) {
    s[x] = max(s[x], seb);
    if (h == H) {
        return;
    }
    in[x] = true;
    for (pii &next : G[x]) {
        if (in[next.first]) {
            continue;
        }
        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);
    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
base15/50
1Accepted0/03ms1892 KiB
2Accepted0/072ms2284 KiB
3Accepted1/13ms2464 KiB
4Accepted1/13ms2680 KiB
5Accepted2/290ms2992 KiB
6Time limit exceeded0/2647ms2816 KiB
7Time limit exceeded0/2554ms2072 KiB
8Time limit exceeded0/2554ms2944 KiB
9Accepted1/14ms3252 KiB
10Time limit exceeded0/1600ms3432 KiB
11Time limit exceeded0/1574ms2756 KiB
12Time limit exceeded0/1565ms3000 KiB
13Time limit exceeded0/2565ms3228 KiB
14Time limit exceeded0/2570ms3476 KiB
15Time limit exceeded0/2561ms3704 KiB
16Time limit exceeded0/2558ms3656 KiB
17Time limit exceeded0/2582ms3756 KiB
18Time limit exceeded0/2555ms3736 KiB
19Time limit exceeded0/2559ms3916 KiB
20Time limit exceeded0/2561ms4128 KiB
21Time limit exceeded0/1569ms4440 KiB
22Time limit exceeded0/1558ms4584 KiB
23Time limit exceeded0/1555ms4800 KiB
24Time limit exceeded0/1566ms4864 KiB
25Time limit exceeded0/2651ms5140 KiB
26Time limit exceeded0/2651ms4924 KiB
27Time limit exceeded0/2555ms5052 KiB
28Accepted2/252ms7004 KiB
29Accepted2/261ms7000 KiB
30Accepted2/259ms7040 KiB
31Accepted2/257ms6948 KiB
32Accepted2/263ms7104 KiB