Google Interview Question

Design encode(root) to serialize all graph nodes reachable from root into a flat list[int], and decode(encoded) to rebuild an isomorphic graph.