  Let $G$ be a nontrivial connected graph with an edge-coloring
$c:E(G)\rightarrow \{1,2,\ldots,q\},$ $q\in \mathbb{N}$, where adjacent edges
may be colored the same. A tree $T$ in $G$ is a $rainbow tree$ if no two edges
of $T$ receive the same color. For a vertex set $S\subseteq V(G)$, the tree
connecting $S$ in $G$ is called an $S$-tree. The minimum number of colors that
are needed in an edge-coloring of $G$ such that there is a rainbow $S$-tree for
each $k$-set $S$ of $V(G)$ is called the $k$-rainbow index of $G$, denoted by
$rx_k(G)$. In \cite{Zhang}, they got that the $k$-rainbow index of a tree is
$n-1$ and the $k$-rainbow index of a unicyclic graph is $n-1$ or $n-2$. So
there is an intriguing problem: Characterize graphs with the $k$-rainbow index
$n-1$ and $n-2$. In this paper, we focus on $k=3$, and characterize the graphs
whose 3-rainbow index is $n-1$ and $n-2$, respectively.
