LinkedForwardStar Link[MAXM << 1]; int Head[MAXN]= {0}; int size = 0;
voidInsert(int u, int v){ Link[++ size].to = v; Link[size].next = Head[u];
Head[u] = size; }
int N, K; int degree[MAXN]= {0};
queue<int> que; int depth[MAXN]= {0}; int total[MAXN]= {0}; voidtoposort(){ for (int i = 1; i <= N; i ++) if (degree[i] == 1) { que.push(i); total[depth[i] = 1] ++; } while (! que.empty()) { int u = que.front(); que.pop(); for (int i = Head[u]; i; i = Link[i].next) { int v = Link[i].to; if ((-- degree[v]) == 1) { total[depth[v] = depth[u] + 1] ++; que.push(v); } } } }
inlineintgetnum(){ int num = 0; char ch = getchar (); while (! isdigit (ch)) ch = getchar (); while (isdigit (ch)) num = (num << 3) + (num << 1) + ch - '0', ch = getchar (); return num; }
intmain(){ N = getnum (), K = getnum (); for (int i = 1; i < N; i ++) { int u = getnum (), v = getnum (); Insert (u, v), Insert (v, u); degree[u] ++, degree[v] ++; } toposort (); int ans = 0; for (int i = 1; i <= N; i ++) ans += min (K << 1, total[i]); printf ("%d\n", ans);