Submission #523937

#TimeUsernameProblemLanguageResultExecution timeMemory
523937qwerasdfzxclFirefighting (NOI20_firefighting)C++14
0 / 100
557 ms37808 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; vector<pair<int, ll>> adj[300300]; pair<int, ll> par[300300]; ll dep[300300]; int deg[300300], visited[300300]; priority_queue<pair<ll, int>> pq; void dfs(int s, int pa = -1){ deg[s] = adj[s].size(); for (auto &v:adj[s]) if (v.first!=pa){ par[v.first] = {s, v.second}; dep[v.first] = dep[s] + v.second; dfs(v.first, s); } } void dfs2(int s, ll K){ visited[s] = 1; for (auto &v:adj[s]) if (!visited[v.first]){ if (v.second<=K) dfs2(v.first, K-v.second); else{ deg[v.first]--; if (deg[v.first]==1) pq.emplace(dep[v.first], v.first); } } } int main(){ int n; ll D; scanf("%d %lld", &n, &D); for (int i=0;i<n-1;i++){ int x, y; ll z; scanf("%d %d %lld", &x, &y, &z); adj[x].emplace_back(y, z); adj[y].emplace_back(x, z); } dfs(1); for (int i=1;i<=n;i++) if (deg[i]==1) pq.emplace(dep[i], i); vector<int> ans; while(!pq.empty()){ auto cur = pq.top(); pq.pop(); if (visited[cur.second]) continue; int s = cur.second; ll rem = D; while(par[s].first && par[s].second<=rem){ rem -= par[s].second; s = par[s].first; } ans.push_back(s); dfs2(s, D); } printf("%d\n", (int)ans.size()); for (auto &x:ans) printf("%d ", x); return 0; }

Compilation message (stderr)

Firefighting.cpp: In function 'int main()':
Firefighting.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d %lld", &n, &D);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
Firefighting.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf("%d %d %lld", &x, &y, &z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...