답안 #1045820

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1045820 2024-08-06T07:57:37 Z gagik_2007 Petrol stations (CEOI24_stations) C++17
18 / 100
33 ms 720 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=5007;
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;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 8 ms 632 KB Output is correct
4 Correct 21 ms 600 KB Output is correct
5 Correct 16 ms 652 KB Output is correct
6 Correct 33 ms 604 KB Output is correct
7 Correct 25 ms 720 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 14 ms 604 KB Output is correct
10 Correct 11 ms 604 KB Output is correct
11 Correct 11 ms 604 KB Output is correct
12 Correct 12 ms 600 KB Output is correct
13 Correct 17 ms 604 KB Output is correct
14 Correct 7 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Runtime error 1 ms 604 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 604 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 604 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 8 ms 632 KB Output is correct
4 Correct 21 ms 600 KB Output is correct
5 Correct 16 ms 652 KB Output is correct
6 Correct 33 ms 604 KB Output is correct
7 Correct 25 ms 720 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 14 ms 604 KB Output is correct
10 Correct 11 ms 604 KB Output is correct
11 Correct 11 ms 604 KB Output is correct
12 Correct 12 ms 600 KB Output is correct
13 Correct 17 ms 604 KB Output is correct
14 Correct 7 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Runtime error 1 ms 604 KB Execution killed with signal 11
17 Halted 0 ms 0 KB -