Let D > 2 be a square-free integer and define a direct graph G(D) such that the vertices of the graph are the primes p i dividing D, and the arcs are determined by conditions on the quadratic residues (p i /p j ). In this paper, our main result is that x 2 − Dy 2 = k, where k = −1, ±2, is solvable if the corresponding graph is "odd". Being "odd" is a complicated technical condition but we obtain a new criterion for the solvability of these diophantine equations which is quite different from that obtained by Yokoi in 1994. The solvability of these diophantine equations are related (by a theorem of Moser) to the stufe (the minimal number of squares −1 is the sum of integral squares) of an imaginary quadratic number field. We obtain an explicit result that the stufe is 2. Finally, we easily prove some results (originally proved by Hsia and Estes) on the expressibility of integers in an imaginary quadratic number field as sums of 3 integral squares.