1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | struct LIST{ //struct HASH{ int in, int out, HASH *prev; }h[max_hash]; int v; int ans; LIST *prev; LIST(){}; LIST(int _v, LIST* prev):v(_v), prev(_prev), ans(-1){}; }a[1000]; //부모 노드 LIST* branch[30]; // LIST* last[max]; //struct NODES{ int parent; .. LIST* last}nodes[max_node]; //HASH* hash_table[hash_size]; int heap_idx; // int hash_idx = 0; int current_branch = 0; // 자식에 넣기 // 링크드 리스트 // 트리- nodes structure에 부모 정보를 넣음 a[heap_idx] = LIST(id, branch[current_branch]); // a[heap_idx] = LIST(id, last[pid]); // a[heap_idx] = LIST(id, nodes[pid].last); branch[current_branch] = &a[heap_idx++]; // last[pid] = &a[heap_idx++]; // nodes[pid].last = &[heap_idx++]; // getIndexFromHash(id) int hashv = in % 1000; for(HASH* e=hash_table[hashv];e;e=e->prev) { if(e->in == id) return e->out; h[hash_idx] = HASH(in, hash_idx, hash_table[hashv]); hash_table[hashv] = &h[hash_idx++]; return hash_idx-1; // 자식 탐색 for(LIST *e=branch[current_branch];e;e=e->prev) { // 자식노드에 부모 마킹하기 //e->v 사용 e->ans = current_branch; } | cs |
알고리즘