\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{parskip}
\usepackage{marvosym} %Lightning symbol
\usepackage[usenames,dvipsnames]{color}
\usepackage[hidelinks]{hyperref}
\renewcommand*{\familydefault}{\sfdefault}

\usepackage{bbm} %For \mathbbm{1}
%\usepackage{bbold}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=0.8]
    \def\width{6};
    \def\height{4};
    %\draw[step=1cm] (0,0) grid (\width,\height);

    % Vertices and edges
    \foreach \x in {0,...,\width} {
        \foreach \y in {0,...,\height} {
            \draw (\x,\y) circle (0.10);
            \ifnum\x<\width
                \draw (\x,\y)+(0.1,0) -- (\x+0.9,\y);
            \fi
            \ifnum\y<\height
                \draw (\x,\y)+(0,0.1) -- (\x,\y+0.9);
            \fi
        }
    }

    %
    % The set S : red circles
    %

    \draw[fill,red] (3,0) circle (0.08);
    \draw[fill,red] (2,1) circle (0.08);
    \draw[fill,red] (3,2) circle (0.08);
    \draw[fill,red] (3,3) circle (0.08);
    \draw[fill,red] (4,4) circle (0.08);

    \draw (3,-0.5) node {$S$};

    % The set X
    \draw[xshift=-0.2cm,dashed] (-0.5,-1.0) -- (2.5,-1.0) -- (2.5,0.5) -- (1.5,0.5) -- (1.5,1.5) -- (2.5,1.5) -- (2.5,3.5) -- (3.5,3.5) -- (3.5,4.5) -- (-0.5,4.5) -- cycle;
    \draw (1,-0.5) node {$X$};

    % The set Y
    \draw[xshift=+0.2cm,dashed] (6.5,-1.0) -- (3.5,-1.0) -- (3.5,0.5) -- (2.5,0.5) -- (2.5,1.5) -- (3.5,1.5) -- (3.5,3.5) -- (4.5,3.5) -- (4.5,4.5) -- (6.5,4.5) -- cycle;
    \draw (5,-0.5) node {$Y$};

\end{tikzpicture}
\end{document}
