let () =
    let main () =
        let n, k = Scanf.sscanf (read_line ()) "%d %d" (fun n k -> n, k) in
        let ab = Array.init (n - 1) (fun _ -> Scanf.sscanf (read_line ()) "%d %d" (fun a b -> a - 1, b - 1)) in
        let hist = Array.make n [] in
        Array.iter (fun (a, b) -> hist.(a) <- b :: hist.(a); hist.(b) <- a :: hist.(b)) ab;
        let ( *@) a b = (a * b) mod 1000000007 in
        let rec color from cur =
            let cl = if from = -1 then k - 1 else k - 2 in
            if List.length hist.(cur) > k then 0 else (
                let (c, _) = List.fold_left (fun (acc, cl) next ->
                    if next = from then (acc, cl) else acc *@ cl, cl - 1) (1, cl) hist.(cur)
                in
                List.fold_left (fun acc next ->
                    if next = from then acc else acc *@ color cur next) c hist.(cur)
            )
        in
        Printf.printf "%d\n" (k *@ color (-1) 0)
    in
    main ()