Well, there are many solutions to your question. The absolute easiest way of doing this, assuming you have a database available, would be to create a table with two columns. E.g., 'field' and 'dep'. 'field' would hold some sort of unique name for a input field (and ofcourse they may use auto_increments as well). The 'dep' would be a reference to another field. E.g.
| field | dep |
|-------|-----|
| A | B |
| A | C |
| C | D |
| F | A |
| A | I |
and so on.
You would then select all entries from this table with 'field' = whatever field you're checking, then spin through the results and check if everything's okay. This is a rather slow solution, but its pretty tidy and otherwise alright (unless you're handling tenthousands of fields and creating unique names is a problem. In that case, you need to add something like 'form id' or something to identify wich form the field belongs to, and it'd only have to be unique within that form).
Another example for solution would be to combine all 'dep' values for one field into one dep field of type text, blob or something, and separate them with commas or similar. This could save you db load when performing selects etc, but needs a bit more "thought" when deleting entries, or when inserting new ones.