void SuffixTree<Symb,NSymb>::SetSuffix() { // recursive procedure SetSuffix(n) processed nodes in post-order; // this one processes in pre-order (it is easier to implement iteratively) // TODO: ratio - more sophisticated choose of long suffix link std::vector<PNode> stack; stack.reserve(STACK_INIT); stack.push_back(ROOT); PNode n, ch; while(!stack.empty()) { n = stack.back(); stack.pop_back(); Node& node = GetNode(n); BHASSERT_WITH_NO_PERFORMANCE_IMPACT(n != NIL); // put children on stack for(ch = node.child; ch != NIL; ch = NxtChild(ch)) stack.push_back(ch); if(n == ROOT) continue; PNode& suf = node.suf; if(data[node.pos + node.len - 1] == '\0') // if the node's edge label ends with '\0', link the suffix directly to the root suf = ROOT; else // find suffix which is not cut off and has signifficantly different distribution than 'n' // TODO: time - optimize searching for the best suffix link while((suf != NIL) && (GetCut(suf) || Similar(n, suf))) suf = GetNode(suf).suf; //if(suf == NIL) suf = ROOT; } }
int main() { while(scanf("%d",&n)!=EOF) { for(int i=0; i<2; i++) for(int j=1; j<=n; j++) scanf("%lf%lf",&p[i][j].x,&p[i][j].y); int flag = 1; for(int i=1; i<=n; i++) { for(int j=0; j<2; j++) { if(Similar(1,i,j)) flag = 0; } if(flag == 0)break; } printf("%s\n",ans[flag]); } return 0; }