답안 #1069994

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069994 2024-08-22T10:53:56 Z YassineBenYounes Petrol stations (CEOI24_stations) C++17
18 / 100
3500 ms 11916 KB
#include <bits/stdc++.h>
using namespace std;
void init(){
    #ifndef ONLINE_JUDGE
 
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
typedef long long ll;
#define vi vector<int>
#define pii pair<int, int >
#define vii vector<pii>
#define ff first
#define ss second
#define pb push_back

const int mx = 7e4+5;
#define int ll
vii graph[mx];

int cnt[mx], sz[mx];
int n, k;
int st;
void pre(int node, int p){
    sz[node] = 1;
    for(pii adj : graph[node]){
        if(adj.ff == p)continue;
        pre(adj.ff, node);
        sz[node] += sz[adj.ff];
    }
}

void dfs(int node, int p, int left){
    for(pii adj : graph[node]){
        if(adj.ff == p)continue;
        int nw = left - adj.ss;
        if(nw < 0){
            cnt[node]+=sz[adj.ff]; 
            dfs(adj.ff, node, k - adj.ss);
        }
        else{
            dfs(adj.ff, node, nw);
        }
    }
}

int32_t main(){
    cin >> n >> k;
    for(int i = 1; i < n;i++){
        int a, b, c;cin >> a >> b >> c;
        graph[a].pb({b, c});
        graph[b].pb({a, c});
    }
    for(int i = 0; i < n;i++){
        pre(i, i);
        dfs(i, i, k);
    }
    for(int i = 0; i < n;i++){
        cout << cnt[i] << endl;
    }
}

Compilation message

Main.cpp: In function 'void init()':
Main.cpp:6:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | freopen("input.txt", "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:7:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | freopen("output.txt", "w", stdout);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 10 ms 3044 KB Output is correct
4 Correct 19 ms 2908 KB Output is correct
5 Correct 13 ms 2904 KB Output is correct
6 Correct 26 ms 2908 KB Output is correct
7 Correct 22 ms 3120 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 17 ms 2908 KB Output is correct
10 Correct 13 ms 3060 KB Output is correct
11 Correct 14 ms 2908 KB Output is correct
12 Correct 13 ms 3160 KB Output is correct
13 Correct 13 ms 3060 KB Output is correct
14 Correct 10 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Execution timed out 3589 ms 11916 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 1 ms 2904 KB Output is correct
4 Execution timed out 3589 ms 11916 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Execution timed out 3560 ms 7508 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Execution timed out 3560 ms 7508 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 10 ms 3044 KB Output is correct
4 Correct 19 ms 2908 KB Output is correct
5 Correct 13 ms 2904 KB Output is correct
6 Correct 26 ms 2908 KB Output is correct
7 Correct 22 ms 3120 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 17 ms 2908 KB Output is correct
10 Correct 13 ms 3060 KB Output is correct
11 Correct 14 ms 2908 KB Output is correct
12 Correct 13 ms 3160 KB Output is correct
13 Correct 13 ms 3060 KB Output is correct
14 Correct 10 ms 2908 KB Output is correct
15 Correct 1 ms 2904 KB Output is correct
16 Execution timed out 3589 ms 11916 KB Time limit exceeded
17 Halted 0 ms 0 KB -