• + 0 comments

    C# one-line

    public static int solve(int n, int m)
    {
        return n == 1 ? m%1000000007: (int)((BigInteger.ModPow(m-2, n-2,1000000007)*m*(m-1)) % 1000000007);
    }
    

    ..without BigInteger would be longer :)