제출 #525103

#제출 시각아이디문제언어결과실행 시간메모리
525103benedict0724Firefighting (NOI20_firefighting)C++17
0 / 100
286 ms25572 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, ll> pi; const ll INF = 1e18; int n; ll k; vector<pi> adj[300002]; bool chk[300002]; int ans = 0; ll dfs(int x, int p, ll d) { vector<ll> v; ll tmp1 = INF, tmp2 = 0; ll D = INF; int t = 1; for(auto u : adj[x]) { int i = u.first; if(i == p) continue; ll c = u.second; ll P = dfs(i, x, c); if(P > 0 && P < tmp1) { tmp1 = P; t = 1; } if(P < 0 && -P > tmp2) { tmp2 = -P; t = -1; } } if(tmp1 == INF && tmp2 == 0) { D = INF; } else if(tmp1 == INF) { D = tmp2; t = -1; } else if(tmp1 > tmp2) { D = tmp1; t = 1; } else { D = tmp2; t = -1; } if(D == INF) { if(d > k) { chk[x] = 1; ans++; return 2*k+2; } return -(d+k+1); } if(D > k && D + d > 2*k+1) { chk[x] = 1; ans++; return min(d, k+1); } else if(D > k) return t*(D+d); if(D + d > k) return t*(k+1); else return t*(D+d); } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; for(int i=1;i<n;i++) { int a, b; ll D; cin >> a >> b >> D; adj[a].push_back({b, D}); adj[b].push_back({a, D}); } ll P = dfs(1, 0, 0); assert(ans <= n); cout << ans << "\n"; for(int i=1;i<=n;i++) if(chk[i]) cout << i << " "; }

컴파일 시 표준 에러 (stderr) 메시지

Firefighting.cpp: In function 'int main()':
Firefighting.cpp:72:8: warning: unused variable 'P' [-Wunused-variable]
   72 |     ll P = dfs(1, 0, 0);
      |        ^
#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...