Submission #1075550

#TimeUsernameProblemLanguageResultExecution timeMemory
1075550ProtonDecay314Petrol stations (CEOI24_stations)C++17
0 / 100
3552 ms5312 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<bool> vb;
typedef set<ll> sll;
#define IOS cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false)
#define INF(dtype) numeric_limits<dtype>::max()
#define NINF(dtype) numeric_limits<dtype>::min()
#define fi first
#define se second
#define pb push_back

typedef vector<vb> vvb;
typedef vector<vvb> v3b;
typedef vector<v3b> v4b;
typedef vector<string> vs;

struct state {
    int i, p;
    int fuel;
};

vi solve(int n, int k, const vvpi& adj) {
    vi ans(n, 0);

    for(int s = 0; s < n; s++) {
        queue<state> q;

        q.push({s, s, k});

        while(!q.empty()) {
            auto [i, p, fuel] = q.front();

            q.pop();

            for(auto [j, l] : adj[i]) {
                if(j == p) continue;

                if(fuel < l) {
                    ans[i] ++;

                    q.push({j, i, k - l});
                } else {
                    q.push({j, i, fuel - l});
                }
            }
        }
    }

    return ans;
}

int main() {
    int n, k; cin >> n >> k;

    vvpi adj;
    for(int i = 0; i < n; i++) {
        vpi adjr;
        adj.pb(adjr);
    }

    for(int i = 0; i < n - 1; i++) {
        int u, v, l;
        cin >> u >> v >> l;

        adj[u].pb({v, l});
        adj[v].pb({u, l});
    }

    vi ans = solve(n, k, adj);

    for(int v : ans) cout << v << " ";

    cout << "\n";
    cout << flush;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...