Pagini recente » Cod sursa (job #1330074) | Cod sursa (job #1619107) | Cod sursa (job #333010) | Cod sursa (job #1423601) | Cod sursa (job #1611602)
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e4 + 5;
short D[NMAX];
struct cmp{
bool operator()(const short &a,const short &b){
return D[a] < D[b];
}
};
priority_queue < short ,vector < short > ,cmp > heap;
vector < short > G[NMAX];
inline void(short k){
short nod;
while(k != n && !heap.empty()){
nod = heap.top();
heap.pop();
if(D[nod] != 0)
D[nod] ++;
for(int i = 0; i < G[nod].size(); i++){
if(D[G[nod][i]] != - 1){
D[G[nod][i]] += 2*D[nod];
if(D[nod] == 0) }
}
}
}
int main()
{
freopen ("cezar.in" , "r", stdin);
freopen ("cezar.out" , "w", stdout);
short n,x,y,k;
scanf("%h %h", &n, &k);
for(int i = 1; i < n ; i++){
scanf("%h %h", &x &y);
G[x].push_back(y);
G[y].push_back(x);
}
for(int i = 1; i <= n; i++){
if(G[i].size() == 1){
heap.push(i);
k++;
}
}
Solve(k,n);
return 0;
}