제출 #1295719

#제출 시각아이디문제언어결과실행 시간메모리
1295719jackofall718Firefighting (NOI20_firefighting)C++20
0 / 100
224 ms23440 KiB
#include <bits/stdc++.h> #include <chrono> #define ll long long int #define endl '\n' #define vn vector<ll> #define vi vector<pair <ll,ll>> using namespace std; using namespace std::chrono; const int MAX_N = 1e9 + 7; #define pii pair<ll,ll> const ll INF = 0x3f3f3f3f3f3f3f3f; #define pb push_back #define srt(vp) sort(vp.begin(), vp.end()) ll n,k; vector <vi> adj; vn ans; pair <ll,ll> dfs(ll n, ll p , ll d){ ll cover=0; ll nah = 0; for (auto &x:adj[n]){ if (x.first==p)continue; auto [child,dist]=x; auto [status,far]=dfs(child,n,dist); if (status){ cover = max(cover,far); } else nah = max(far,nah); } if (cover >= nah){ if (cover >= d)return {1,cover-d}; else return {0,0}; } else{ if (nah + d <=k)return {0,nah+d}; else{ ans.pb(n); if (k >=d)return {1,k-d}; else return {0,0}; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); auto start = high_resolution_clock::now(); cin>>n>>k; adj.resize(n+1); for (int i=0;i<n-1;i++){ ll a,b,c; cin>>a>>b>>c; adj[a].pb({b,c}); adj[b].pb({a,c}); } if (dfs(1,0,0).first==0)ans.pb(1); auto stop = high_resolution_clock::now(); auto duration = duration_cast<microseconds>(stop - start); //cout << "Time taken by function: " << duration.count() << " microseconds" << endl; return 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...