Submission #1069994

#TimeUsernameProblemLanguageResultExecution timeMemory
1069994YassineBenYounesPetrol stations (CEOI24_stations)C++17
18 / 100
3589 ms11916 KiB
#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 (stderr)

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);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...