There's probably a simpler way, but I think this query returns what you want:
MATCH (m)-[r:topicOf]->(n)
WITH collect(m) AS m_nodes, collect(n) AS n_nodes
UNWIND m_nodes AS m
UNWIND labels(m) AS m_label
WITH n_nodes, collect(distinct m_label) AS m_labels
UNWIND n_nodes AS n
UNWIND labels(n) AS n_label
WITH m_labels, collect(distinct n_label) AS n_labels
RETURN m_labels, n_labels