Update trie.cpp

Fixing a bug in building fail node function.
Adding ID assignment.