$2g=da+ma_1-2a-d-m+2$, where $a=a_1m,$ and $m$ is the g.c.d ($d,a$).
Edit.
Let $\chi(S)=2-2g$ be the Euler characteristic. Hurwitz formula gives
$$\chi(S)=2a-r,$$
where $r$ is the ramification: a branch point of order $k$ contributes
$k-1$ to $r$. As your polynomial has $d$ simple roots, these roots
contribute $(a-1)d$ to the ramification. To find ramification at infinity
we write our equation $w^a=P_d(z)$ as $w^a=z^dh(z)=u^d$,
where $h$ is a holomorphic function at $\infty$,
$h(\infty)\neq 0$, and $u$ a germ of a
meromorphic function with a simple pole at $\infty$.
The last equation factors into irreducible factors:
$$w^a-u^d=\prod_c (w^{a_1}-cu^{d_1}),$$
where $c$ are the roots of unity of degree $m$, $m$ is the greatest
common factor of $a$ and $d$, $d=md_1,$ and $a=ma_1$.
From this we conclude that our Riemann surface $S$ has $m$ ramification
points of order $a_1$ at $\infty$. So we obtain
$$2-2g=2a-(a-1)d-m(a_1-1).$$