답안 #1113769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113769 2024-11-17T11:51:20 Z Zero_OP Petrol stations (CEOI24_stations) C++14
18 / 100
25 ms 760 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX = 1e3 + 5;

int N, K, ans[MAX], sz[MAX];
vector<pair<int, int>> adj[MAX];

void dfs_sz(int u, int pre){
    sz[u] = 1;
    for(auto [v, l] : adj[u]) if(v != pre){
        dfs_sz(v, u);
        sz[u] += sz[v];
    }
}

void dfs(int u, int pre, int left){
    for(auto [v, l] : adj[u]) if(v != pre){
        if(left < l) {
            ans[u] += sz[v], dfs(v, u, K - l);
        }
        else dfs(v, u, left - l);
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N >> K;
    for(int i = 1; i < N; ++i){
        int u, v, l;
        cin >> u >> v >> l;
        adj[u].emplace_back(v, l);
        adj[v].emplace_back(u, l);
    }

    for(int i = 0; i < N; ++i){
        dfs_sz(i, -1);
        dfs(i, -1, K);
    }

    for(int i = 0; i < N; ++i){
        cout << ans[i] << '\n';
    }

    return 0;
}

Compilation message

Main.cpp: In function 'void dfs_sz(int, int)':
Main.cpp:12:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   12 |     for(auto [v, l] : adj[u]) if(v != pre){
      |              ^
Main.cpp: In function 'void dfs(int, int, int)':
Main.cpp:19:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   19 |     for(auto [v, l] : adj[u]) if(v != pre){
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 11 ms 336 KB Output is correct
4 Correct 19 ms 544 KB Output is correct
5 Correct 11 ms 336 KB Output is correct
6 Correct 25 ms 592 KB Output is correct
7 Correct 23 ms 760 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 12 ms 536 KB Output is correct
10 Correct 12 ms 336 KB Output is correct
11 Correct 13 ms 544 KB Output is correct
12 Correct 13 ms 336 KB Output is correct
13 Correct 14 ms 508 KB Output is correct
14 Correct 9 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Runtime error 2 ms 592 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Runtime error 2 ms 592 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Runtime error 2 ms 592 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Runtime error 2 ms 592 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 11 ms 336 KB Output is correct
4 Correct 19 ms 544 KB Output is correct
5 Correct 11 ms 336 KB Output is correct
6 Correct 25 ms 592 KB Output is correct
7 Correct 23 ms 760 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 12 ms 536 KB Output is correct
10 Correct 12 ms 336 KB Output is correct
11 Correct 13 ms 544 KB Output is correct
12 Correct 13 ms 336 KB Output is correct
13 Correct 14 ms 508 KB Output is correct
14 Correct 9 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Runtime error 2 ms 592 KB Execution killed with signal 11
17 Halted 0 ms 0 KB -