What kind of an object is the derivative $df$ of a discrete function? It is a map
$\omega: E \rightarrow \mathbb{R}$
such that
$\omega \circ \rho = -\omega$.
We call such an $\omega$ a discrete 1-form and denote the vector space of all discrete 1-forms by $\Omega_1(M)$. Discrete functions are also called 0-forms on $M$ and the space of all 0-forms is denoted by $\Omega_0(M)$.
We want to ask which 1-forms $\omega$ are of the form $df$ for some discrete function $f$. If this is the case, $f$ is called a primitive of $\omega$ and $\omega$ is called exact. This means we want to know the image of the linear map
$d: \Omega_0(M) \rightarrow \Omega_1(M)$.
This sounds similar to a problem studied in any introductory calculus course: Given a vector field on some open set $U \subset \mathbb{R}^n$, determine whether it is the gradient of a function $f: U \rightarrow \mathbb{R}$. We will procede in the discrete case in a way that hopefully will make clear that even the statements and proofs are very similar in the discrete case to the smooth setting.
If $\gamma = (e_1, \ldots , e_m)$ is a path in $M$ and $\omega \in \Omega_1(M)$ then we define
$\displaystyle \int_\gamma \omega := \sum_{k=1}^m \omega(e_k)$.
We define
$\textrm{start}(\gamma):= \textrm{start}(e_1)$
$\textrm{end}(\gamma):= \textrm{end}(e_m)$.
A nice analogue of the fundamental theorem of calculus is then the (easy to prove) statement
$\displaystyle \int_\gamma df = f(\textrm{end}(\gamma))-(f(\textrm{start}(\gamma))$.
A path $\gamma$ is called closed if
$\textrm{end}(\gamma) =\textrm{start}(\gamma)$.
Thus a necessary condition for $\omega$ to be exact is that
$\displaystyle \int_\gamma \omega =0$
for every closed path $\gamma$ in $M$. This condition is in fact also sufficient:
Theorem: A 1-form $\omega$ on $M$ is exact if and only if the integral of $\omega$ over any closed path $\gamma$ in $M$ vanishes.
Proof: Assume the integral of $\omega$ over any closed path $\gamma$ vanishes. Choose a vertex $i \in V$ and define $f(i)=0$. For any vertex $j$ in the same connected component as $i$ choose a path $\gamma_j$ from $i$ to $j$ and define
$\displaystyle f(j):=\int_{\gamma_j} \omega$.
We claim that this definition is in fact independent of the choice of $\gamma_j$. If $\tilde{\gamma} = (\tilde{e}_1, \ldots, \tilde{e}_\tilde{m})$ is another path from $i$ to $j$ then
$\gamma := (e_1, \ldots ,e_m, \rho(\tilde{e}_{\tilde{m}}), \ldots \rho(\tilde{e}_1))$
is closed and therefore
$\displaystyle 0 = \int_{\gamma} \omega = \int_{\gamma_j} \omega – \int_{\tilde{\gamma}} \omega$.
Now we can show $df = \omega$, at least on the connected component of the vertex $i$: Let $e$ be an edge in this component and choose a path $\gamma = (e_1,\ldots ,e_m)$ from $i$ to $\textrm{start}(e)$. Then $\tilde{\gamma}=(e_1, \ldots ,e_m, e)$ is a path from $i$ to $\textrm{end}(e)$ and
$\displaystyle df(e) = f(\textrm{end}(e)-\textrm{start}(e)=\int_{\tilde{\gamma}}\omega -\int_\gamma \omega = \omega(e)$.
Repeating this construction on all connected components of $M$ we get the desired primitive $f$ of $\omega$ on the whole of $M$.
$\square$