description: Two players, Red and Blue, are at it again, and this time they're playing with crayons! The mischievous duo is now vandalizing a rooted tree, by coloring the nodes while playing their favorite game.
  
  The game works as follows: there is a tree of size n, rooted at node 1, where each node is initially white. Red and Blue get one turn each. Red goes first. 
  
  In Red's turn, he can do the following operation any number of times: 
  
    * Pick any subtree of the rooted tree, and color every node in the subtree red. 
  
  However, to make the game fair, Red is only allowed to color k nodes of the tree. In other words, after Red's turn, at most k of the nodes can be colored red.
  
  Then, it's Blue's turn. Blue can do the following operation any number of times: 
  
    * Pick any subtree of the rooted tree, and color every node in the subtree blue. However, he's not allowed to choose a subtree that contains a node already colored red, as that would make the node purple and no one likes purple crayon. 
  
  Note: there's no restriction on the number of nodes Blue can color, as long as he doesn't color a node that Red has already colored.
  
  After the two turns, the score of the game is determined as follows: let w be the number of white nodes, r be the number of red nodes, and b be the number of blue nodes. The score of the game is w ⋅ (r - b).
  
  Red wants to maximize this score, and Blue wants to minimize it. If both players play optimally, what will the final score of the game be?
  
  Input
  
  The first line contains two integers n and k (2 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ n) — the number of vertices in the tree and the maximum number of red nodes.
  
  Next n - 1 lines contains description of edges. The i-th line contains two space separated integers u_i and v_i (1 ≤ u_i, v_i ≤ n; u_i ≠ v_i) — the i-th edge of the tree.
  
  It's guaranteed that given edges form a tree.
  
  Output
  
  Print one integer — the resulting score if both Red and Blue play optimally.
  
  Examples
  
  Input
  
  
  4 2
  1 2
  1 3
  1 4
  
  
  Output
  
  
  1
  
  
  Input
  
  
  5 2
  1 2
  2 3
  3 4
  4 5
  
  
  Output
  
  
  6
  
  
  Input
  
  
  7 2
  1 2
  1 3
  4 2
  3 5
  6 3
  6 7
  
  
  Output
  
  
  4
  
  
  Input
  
  
  4 1
  1 2
  1 3
  1 4
  
  
  Output
  
  
  -1
  
  Note
  
  In the first test case, the optimal strategy is as follows: 
  
    * Red chooses to color the subtrees of nodes 2 and 3. 
    * Blue chooses to color the subtree of node 4. 
  
  At the end of this process, nodes 2 and 3 are red, node 4 is blue, and node 1 is white. The score of the game is 1 ⋅ (2 - 1) = 1.
  
  In the second test case, the optimal strategy is as follows: 
  
    * Red chooses to color the subtree of node 4. This colors both nodes 4 and 5. 
    * Blue does not have any options, so nothing is colored blue. 
  
  At the end of this process, nodes 4 and 5 are red, and nodes 1, 2 and 3 are white. The score of the game is 3 ⋅ (2 - 0) = 6.
  
  For the third test case:
  
  <image>
  
  The score of the game is 4 ⋅ (2 - 1) = 4.
solution: /*
  stream Butter!
  eggyHide eggyVengeance
  I need U
  xiao rerun when
   */
  import static java.lang.Math.*;
  import java.util.*;
  import java.io.*;
  import java.math.*;
  
  public class x1615E
  {
      static ArrayDeque<Integer>[] edges;
      public static void main(String hi[]) throws Exception
      {
          FastScanner infile = new FastScanner();
          int N = infile.nextInt();
          int K = infile.nextInt();
          edges = new ArrayDeque[N];
          for(int i=0; i < N; i++)
              edges[i] = new ArrayDeque<Integer>();
          for(int i=1; i < N; i++)
          {
              int a = infile.nextInt()-1;
              int b = infile.nextInt()-1;
              edges[a].add(b);    edges[b].add(a);
          }
          int leaves = 0;
          for(int v=1; v < N; v++)
              if(edges[v].size() == 1)
                  leaves++;
          //generate parent array and depths
          int[] parent = new int[N];
          int[] depth = new int[N];
          parent[0] = -1;
          depth[0] = 1;
          ArrayList<Integer> tour = new ArrayList<Integer>();
          dfs(0, -1, tour, parent, depth);
          //throw leaves into segment tree
          LazySegTree st = new LazySegTree(tour.size());
          int[] left = new int[N];
          int[] right = new int[N];
          Arrays.fill(left, -1);
          for(int i=0; i < tour.size(); i++)
          {
              if(left[tour.get(i)] == -1)
                  left[tour.get(i)] = i;
              else
                  right[tour.get(i)] = i;
          }
          for(int v=0; v < N; v++)
              st.update(left[v], left[v], depth[v]);
          long res = Long.MIN_VALUE/2;
          long white = 0;
          for(int turn=0; turn < min(K, leaves); turn++)
          {
              int toRemove = tour.get(find(tour.size(), st));
              int chainLength = st.query(0, tour.size()-1);
              white += chainLength-1;
              //go up tree and make changes
              int curr = toRemove;
              int previous = -1;
              while(chainLength > 0)
              {
                  for(int next: edges[curr])
                      if(next != parent[curr] && next != previous)
                          st.update(left[next], right[next], -1*chainLength);
                  st.update(left[curr], left[curr], -1*chainLength);
                  previous = curr;
                  curr = parent[curr];
                  chainLength--;
              }
              long blue = N-(turn+1)-white;
              long choice = white*(turn+1-blue);
              //ternary search
              long low = 0L;
              long high = blue;
              while(low+3 < high)
              {
                  long diff = (high-low)/3;
                  long lmid = low+diff;
                  long rmid = high-diff;
                  if(calc(N-(turn+1)-lmid,turn+1, lmid) <= calc(N-(turn+1)-rmid, turn+1, rmid))
                      high = rmid;
                  else
                      low = lmid;
              }
              for(long b=low; b <= high; b++)
                  choice = min(choice, calc(N-(turn+1)-b, turn+1, b));
              res = max(res, choice);
          }
          if(leaves < K)
          {
              for(int v=leaves+1; v <= K; v++)
                  res = max(res, (long)(N-v)*v);
          }
          System.out.println(res);
      }
      public static long calc(long W, long R, long B)
      {
          return W*(R-B);
      }
      public static void dfs(int curr, int prev, ArrayList<Integer> tour, int[] parent, int[] depth)
      {
          tour.add(curr);
          for(int next: edges[curr])
              if(next != prev)
              {
                  parent[next] = curr;
                  depth[next] = depth[curr]+1;
                  dfs(next, curr, tour, parent, depth);
              }
          tour.add(curr);
      }
      public static int find(int N, LazySegTree st)
      {
          int bestD = st.query(0, N-1);
          int low = 0;
          int high = N-1;
          while(low != high)
          {
              int mid = (low+high)>>1;
              if(st.query(0, mid) == bestD)
                  high = mid;
              else
                  low = mid+1;
          }
          return low;
      }
  }
  class Leaf implements Comparable<Leaf>
  {
      public int id;
      public int depth;
  
      public Leaf(int a, int d)
      {
          id = a;
          depth = d;
      }
      public int compareTo(Leaf oth)
      {
          if(depth == oth.depth)
              return id-oth.id;
          return oth.depth-depth;
      }
  }
  class LazySegTree
  {
      //definitions
      private int NULL = -1;
      private int[] tree;
      private int[] lazy;
      private int length;
  
      public LazySegTree(int N)
      {
          length = N;   int b;
          for(b=0; (1<<b) < length; b++);
          tree = new int[1<<(b+1)];
          lazy = new int[1<<(b+1)];
      }
      public int query(int left, int right)
      {
          //left and right are 0-indexed
          return get(1, 0, length-1, left, right);
      }
      private int get(int v, int currL, int currR, int L, int R)
      {
          if(L > R)
              return NULL;
          if(L <= currL && currR <= R)
              return tree[v];
          propagate(v);
          int mid = (currL+currR)/2;
          return comb(get(v*2, currL, mid, L, Math.min(R, mid)),
                  get(v*2+1, mid+1, currR, Math.max(L, mid+1), R));
      }
      public void update(int left, int right, int delta)
      {
          add(1, 0, length-1, left, right, delta);
      }
      private void add(int v, int currL, int currR, int L, int R, int delta)
      {
          if(L > R)
              return;
          if(currL == L && currR == R)
          {
              //exact covering
              tree[v] += delta;
              lazy[v] += delta;
              return;
          }
          propagate(v);
          int mid = (currL+currR)/2;
          add(v*2, currL, mid, L, Math.min(R, mid), delta);
          add(v*2+1, mid+1, currR, Math.max(L, mid+1), R, delta);
          tree[v] = comb(tree[v*2], tree[v*2+1]);
      }
      private void propagate(int v)
      {
          //tree[v] already has lazy[v]
          if(lazy[v] == 0)
              return;
          tree[v*2] += lazy[v];
          lazy[v*2] += lazy[v];
          tree[v*2+1] += lazy[v];
          lazy[v*2+1] += lazy[v];
          lazy[v] = 0;
      }
      private int comb(int a, int b)
      {
          return max(a,b);
      }
  }
  class FastScanner
  {
      //I don't understand how this works lmao
      private int BS = 1 << 16;
      private char NC = (char) 0;
      private byte[] buf = new byte[BS];
      private int bId = 0, size = 0;
      private char c = NC;
      private double cnt = 1;
      private BufferedInputStream in;
  
      public FastScanner() {
          in = new BufferedInputStream(System.in, BS);
      }
  
      public FastScanner(String s) {
          try {
              in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
          } catch (Exception e) {
              in = new BufferedInputStream(System.in, BS);
          }
      }
  
      private char getChar() {
          while (bId == size) {
              try {
                  size = in.read(buf);
              } catch (Exception e) {
                  return NC;
              }
              if (size == -1) return NC;
              bId = 0;
          }
          return (char) buf[bId++];
      }
  
      public int nextInt() {
          return (int) nextLong();
      }
  
      public int[] nextInts(int N) {
          int[] res = new int[N];
          for (int i = 0; i < N; i++) {
              res[i] = (int) nextLong();
          }
          return res;
      }
  
      public long[] nextLongs(int N) {
          long[] res = new long[N];
          for (int i = 0; i < N; i++) {
              res[i] = nextLong();
          }
          return res;
      }
  
      public long nextLong() {
          cnt = 1;
          boolean neg = false;
          if (c == NC) c = getChar();
          for (; (c < '0' || c > '9'); c = getChar()) {
              if (c == '-') neg = true;
          }
          long res = 0;
          for (; c >= '0' && c <= '9'; c = getChar()) {
              res = (res << 3) + (res << 1) + c - '0';
              cnt *= 10;
          }
          return neg ? -res : res;
      }
  
      public double nextDouble() {
          double cur = nextLong();
          return c != '.' ? cur : cur + nextLong() / cnt;
      }
  
      public double[] nextDoubles(int N) {
          double[] res = new double[N];
          for (int i = 0; i < N; i++) {
              res[i] = nextDouble();
          }
          return res;
      }
  
      public String next() {
          StringBuilder res = new StringBuilder();
          while (c <= 32) c = getChar();
          while (c > 32) {
              res.append(c);
              c = getChar();
          }
          return res.toString();
      }
  
      public String nextLine() {
          StringBuilder res = new StringBuilder();
          while (c <= 32) c = getChar();
          while (c != '\n') {
              res.append(c);
              c = getChar();
          }
          return res.toString();
      }
  
      public boolean hasNext() {
          if (c > 32) return true;
          while (true) {
              c = getChar();
              if (c == NC) return false;
              else if (c > 32) return true;
          }
      }
  }