trie树(字典树)学习笔记
例题 于是他错误的点名开始了 #include <cstdio> #include <algorithm> #include <cstring> using namespace std; struct node { bool wrd, vis; int ch[26]; }trie[500009]; int siz = 1; inline void insert(char* str) { int t = 1, len = strlen(str); for(int i = 0; i < len; i++) { if(!trie[t].ch[str[i] - 'a']) t = trie[t].ch[str[i] - 'a'] = ++siz; else t = trie[t].ch[str[i] - 'a']; } trie[t].wrd = true; } inline int search(char* str) { int t = 1, len = strlen(str); for(int i = 0; i < len; i++) { if(!trie[t].ch[str[i] - 'a']) return 0; else t = trie[t].ch[str[i] - 'a']; } if(trie[t].wrd) { if(trie[t].vis) return -1;