Submission #468735

#TimeUsernameProblemLanguageResultExecution timeMemory
468735RedmoonautumnMousetrap (CEOI17_mousetrap)C++17
0 / 100
858 ms62856 KiB
#include <bits/stdc++.h> using namespace std; #define int int64_t vector<vector<int>> graph; int dfs2(int v, int p){ priority_queue<int> pq; for(auto u:graph[v]){ if(u==p)continue; int x=dfs2(u,v); pq.push(x); } int sum=0; int i=0; while (!pq.empty()){ sum++; if(i%2)sum+=pq.top(); i++; pq.pop(); } return sum; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n,t,m; cin>>n>>t>>m; graph.resize(n); t--; m--; for(int i=0;i<n-1;i++){ int a,b; cin>>a>>b; a--; b--; graph[a].push_back(b); graph[b].push_back(a); } int sol=dfs2(m,t); cout<<sol<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...