Submission #1045824

# Submission time Handle Problem Language Result Execution time Memory
1045824 2024-08-06T07:58:09 Z gagik_2007 Petrol stations (CEOI24_stations) C++17
18 / 100
3500 ms 11736 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define ff first
#define ss second

ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=70007;
ll n,m,k;
int sz[N];
vector<pair<int,ll>>g[N];
int ans[N];

void calcsz(int v, int par){
    sz[v]=1;
    for(auto e:g[v]){
        int to=e.ff;
        if(to!=par){
            calcsz(to,v);
            sz[v]+=sz[to];
        }
    }
}

void dfs(int v, int par, ll cur){
    // cout<<"TAZA DFS"<<endl;
    for(auto e:g[v]){
        int to=e.ff;
        ll w=e.ss;
        // cout<<"dfs: "<<v<<" "<<par<<" "<<cur<<endl;
        // cout<<"edge: "<<to<<" "<<w<<endl;
        if(to!=par){
            if(cur+w>k){
                // cout<<to<<" "<<cur<<endl;
                ans[v]+=sz[to];
                dfs(to,v,w);
            }
            else{
                dfs(to,v,cur+w);
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // freopen("Einput.txt","r",stdin);
    // freopen("Eoutput.txt","w",stdout);
    cin>>n>>k;
    for(int i=0;i<n-1;i++){
        int u,v;
        ll w;
        cin>>u>>v>>w;
        g[u].push_back({v,w});
        g[v].push_back({u,w});
    }
    for(int v=0;v<n;v++){
        // cout<<"root: "<<v<<endl;
        calcsz(v,-1);
        dfs(v,-1,0);
    }
    for(int v=0;v<n;v++){
        cout<<ans[v]<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2136 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2136 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 8 ms 2160 KB Output is correct
4 Correct 17 ms 2176 KB Output is correct
5 Correct 12 ms 2172 KB Output is correct
6 Correct 23 ms 2140 KB Output is correct
7 Correct 19 ms 2256 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 11 ms 2164 KB Output is correct
10 Correct 13 ms 2136 KB Output is correct
11 Correct 11 ms 2140 KB Output is correct
12 Correct 17 ms 2140 KB Output is correct
13 Correct 14 ms 2136 KB Output is correct
14 Correct 11 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2136 KB Output is correct
2 Execution timed out 3569 ms 11736 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2136 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 2136 KB Output is correct
4 Execution timed out 3569 ms 11736 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2136 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Execution timed out 3541 ms 6236 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2136 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Execution timed out 3541 ms 6236 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2136 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 8 ms 2160 KB Output is correct
4 Correct 17 ms 2176 KB Output is correct
5 Correct 12 ms 2172 KB Output is correct
6 Correct 23 ms 2140 KB Output is correct
7 Correct 19 ms 2256 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 11 ms 2164 KB Output is correct
10 Correct 13 ms 2136 KB Output is correct
11 Correct 11 ms 2140 KB Output is correct
12 Correct 17 ms 2140 KB Output is correct
13 Correct 14 ms 2136 KB Output is correct
14 Correct 11 ms 2140 KB Output is correct
15 Correct 1 ms 2136 KB Output is correct
16 Execution timed out 3569 ms 11736 KB Time limit exceeded
17 Halted 0 ms 0 KB -