  In this paper, we establish optimal Berry--Esseen bounds for the generalized
$U$-statistics. The proof is based on a new Berry--Esseen theorem for
exchangeable pair approach by Stein's method under a general linearity
condition setting. As applications, an optimal convergence rate of the normal
approximation for subgraph counts in Erd\"os--R\'enyi graphs and graphon-random
graph is obtained.
