int main() { int n; bool blank = false; while(cin >> n && n) { num=0; if(blank) cout << endl; blank=true; configs.clear(); corpus.clear(); in_stack.clear(); ssc_stack.clear(); memset(matr,0,sizeof matr); memset(dfs_num,-1,sizeof dfs_num); memset(dfs_low,-1,sizeof dfs_low); char c1,c2,c3,c4,c5,c6; for(int i =0; i < n; ++i) { cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6; if(c1 != c6)matr[c6-'A'][c1-'A'] = 1; if(c2 != c6)matr[c6-'A'][c2-'A'] = 1; if(c3 != c6)matr[c6-'A'][c3-'A'] = 1; if(c4 != c6)matr[c6-'A'][c4-'A'] = 1; if(c5 != c6)matr[c6-'A'][c5-'A'] = 1; corpus.insert(c1-'A'); corpus.insert(c2-'A'); corpus.insert(c3-'A'); corpus.insert(c4-'A'); corpus.insert(c5-'A'); corpus.insert(c6-'A'); } for(const auto& x : corpus) { if(dfs_num[x] == -1) tarjan_ssc(x); } sort(configs.begin(),configs.end()); for(int i =0 ; i < configs.size(); ++i) { cout << configs[i][0]; for(int q =1; q < configs[i].length(); ++q) { cout << " " << configs[i][q]; } cout << endl; } } return 0; }
int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int TC; cin >> TC; for(int tc = 1; tc <= TC; ++tc){ clean(); cin >> n; //fills graph for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ int temp; cin >> temp; v[i][j] = temp; } } visited.clear(); //looks which nodes are reachable from 0 dfs(0, -1); unordered_set<int> cero = visited; for(auto &a: cero){ dom[0][a] = 1; } //runs dfs on graph ignoring node i and sees which nodes are no longer reachable for(int i = 1; i < n; ++i){ visited.clear(); dfs(0, i); for(auto &a: cero){ if(!visited.count(a)){ dom[i][a] = 1; } } } //outputs dominating table cout << "Case " << tc << ":\n+"; for(int j = 0; j < (n*2)-1; ++j){ cout << "-"; } cout << "+\n"; for(int i = 0; i < n; ++i){ cout << "|"; for(int j = 0; j < n; ++j){ cout << ((dom[i][j])? "Y": "N") << "|"; } cout << "\n+"; for(int j = 0; j < (n*2)-1; ++j){ cout << "-"; } cout << "+\n"; } } return 0; }
int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string word, b; getline(cin, word); while(word != ""){ for(int i = 0; i < 17; ++i){ lengths[i].clear(); } back.clear(); visited.clear(); g.clear(); dic.clear(); dic.insert(word); lengths[word.size()].push_back(word); while(getline(cin,word) && word != ""){ //fills dictionary if(!dic.count(word)){ dic.insert(word); for(auto &c: lengths[word.size()]){ if(c.size() > word.size()) break; if(dif1(word, c)){ g[word].push_back(c); g[c].push_back(word); } } lengths[word.size()].push_back(word); } } //runs test cases getline(cin, word); while(word != ""){ reset(); stringstream ss(word); ss >> word >> b; if(word == b) cout << word; else if(bfs(word, b)){ cout << word; print(b); }else cout << "No solution."; getline(cin, word); cout << "\n" << ((word != "")? "\n": ""); visited.clear(); } getline(cin, word); if(word != "") cout << "\n"; } return 0; }
void MMSBModel::SampleMinibatch(unordered_set<VIndex>& vertex_batch, set<pair<VIndex, VIndex> >& link_batch, const Count batch_size) { vertex_batch.clear(); for (int i = 0; i < batch_size; ++i) { while (true) { // randomly sample a vertex from the map<.,.> vertices_ auto it = vertices_.begin(); uint32 nstep = Context::randUInt64() % vertices_.size(); std::advance(it, nstep); VIndex v = it->first; if (vertex_batch.find(v) == vertex_batch.end()) { // to avoid duplicate vertex_batch.insert(v); break; } } } CollectLinks(link_batch, vertex_batch); for (const auto& link : link_batch) { vertex_batch.insert(link.first); vertex_batch.insert(link.second); } //LOG(INFO) // << "iter " << iter_ << ", " // << vertex_batch.size() << " vertexes, " // << link_batch.size() << " links"; }
static void manageConstructionEvent(color_ostream& out) { if ( handlers[EventType::CONSTRUCTION].empty() ) return; unordered_set<df::construction*> constructionsNow(df::global::world->constructions.begin(), df::global::world->constructions.end()); multimap<Plugin*,EventHandler> copy(handlers[EventType::CONSTRUCTION].begin(), handlers[EventType::CONSTRUCTION].end()); for ( auto a = constructions.begin(); a != constructions.end(); a++ ) { df::construction* construction = *a; if ( constructionsNow.find(construction) != constructionsNow.end() ) continue; for ( auto b = copy.begin(); b != copy.end(); b++ ) { EventHandler handle = (*b).second; handle.eventHandler(out, (void*)construction); } } for ( auto a = constructionsNow.begin(); a != constructionsNow.end(); a++ ) { df::construction* construction = *a; if ( constructions.find(construction) != constructions.end() ) continue; for ( auto b = copy.begin(); b != copy.end(); b++ ) { EventHandler handle = (*b).second; handle.eventHandler(out, (void*)construction); } } constructions.clear(); constructions.insert(constructionsNow.begin(), constructionsNow.end()); }
void findNeighborPoints(vtkDataSet* data, vtkIdType ptId, unordered_set<vtkIdType>& nbrs, vtkIdList* cellIds, vtkIdTypeArray* neighbors = NULL) { nbrs.clear(); cellIds->Reset(); data->GetPointCells(ptId, cellIds); for (size_t k = 0; k < cellIds->GetNumberOfIds(); k++) { vtkCell* cell = data->GetCell(cellIds->GetId(k)); for (size_t l = 0; l < cell->GetNumberOfEdges(); l++) { vtkCell* edge = cell->GetEdge(l); vtkIdType s = edge->GetPointId(0); vtkIdType e = edge->GetPointId(1); vtkIdType n = -1; if (s == ptId) { n = e; } else if (e == ptId) { n = s; } if (n > -1) { if (nbrs.find(n) == nbrs.end()) { nbrs.insert(n); if (neighbors != NULL) { neighbors->SetComponent(ptId, nbrs.size() - 1, n); } } } } } }
int main(int argc, char * argv[]) { if (argc <= 2) { printf("usage : mvcas gameid algorithm prejudgesize\n, gameid in 1..100, \n algorithm: \tO for order_id\n"); printf("\tD for degree-decrease\n\tM for modecount\n\tR for random\t"); return 0; } int gameid; sscanf(argv[1],"%d",&gameid); // printf("%d gameid",gameid); readgraph(gameid); memset(degree,0,sizeof(degree)); visitedmaskset.clear(); if (argc>=4) {needprejudge = true; sscanf(argv[3],"%d",&prejudgesize); } for (int i = 0 ; i < map_n ; i++) for (int j = 0 ; j < map_n ; j++) if (graph[i][j]) degree[i]++; if (argv[2][0] =='O') dfs((1<<map_n)-1,map_ans,original_order_func,0); else if (argv[2][0] =='D') dfs((1<<map_n)-1,map_ans,degree_order_func,0); else if (argv[2][0] =='M') { loadmode(); dfs((1<<map_n)-1,map_ans,mode_order_func,0); } else if (argv[2][0] =='R') dfs((1<<map_n)-1,map_ans,random_order_func,0); if (totcnt>MAXX) printf("tot backtrack count > %d\n",MAXX); else printf("gid=,%d, btcnt=,%d, method=,%s,prejudgesize=,%d\n",gameid,totcnt,argv[2],prejudgesize); }
box random_icp::solve(box b, double const precision ) { thread_local static unordered_set<shared_ptr<constraint>> used_constraints; used_constraints.clear(); thread_local static vector<box> solns; thread_local static vector<box> box_stack; solns.clear(); box_stack.clear(); box_stack.push_back(b); do { DREAL_LOG_INFO << "random_icp::solve - loop" << "\t" << "box stack Size = " << box_stack.size(); b = box_stack.back(); box_stack.pop_back(); try { m_ctc.prune(b, m_config); auto this_used_constraints = m_ctc.used_constraints(); used_constraints.insert(this_used_constraints.begin(), this_used_constraints.end()); } catch (contractor_exception & e) { // Do nothing } if (!b.is_empty()) { tuple<int, box, box> splits = b.bisect(precision); int const i = get<0>(splits); if (i >= 0) { box const & first = get<1>(splits); box const & second = get<2>(splits); if (random_bool()) { box_stack.push_back(second); box_stack.push_back(first); } else { box_stack.push_back(first); box_stack.push_back(second); } if (m_config.nra_proof) { m_config.nra_proof_out << "[branched on " << b.get_name(i) << "]" << endl; } } else { m_config.nra_found_soln++; if (m_config.nra_found_soln >= m_config.nra_multiple_soln) { break; } if (m_config.nra_multiple_soln > 1) { // If --multiple_soln is used output_solution(b, m_config, m_config.nra_found_soln); } solns.push_back(b); } } } while (box_stack.size() > 0); m_ctc.set_used_constraints(used_constraints); if (m_config.nra_multiple_soln > 1 && solns.size() > 0) { return solns.back(); } else { assert(!b.is_empty() || box_stack.size() == 0); return b; } }
box naive_icp::solve(box b, contractor & ctc, scoped_vec<shared_ptr<constraint>> const & ctrs, SMTConfig & config, BranchHeuristic& brancher) { thread_local static unordered_set<shared_ptr<constraint>> used_constraints; used_constraints.clear(); thread_local static vector<box> solns; thread_local static vector<box> box_stack; solns.clear(); box_stack.clear(); box_stack.push_back(b); do { DREAL_LOG_INFO << "naive_icp::solve - loop" << "\t" << "box stack Size = " << box_stack.size(); b = box_stack.back(); box_stack.pop_back(); prune(b, ctc, config, used_constraints); if (!b.is_empty()) { if (config.nra_use_stat) { config.nra_stat.increase_branch(); } vector<int> sorted_dims = brancher.sort_branches(b, ctrs, config); if (sorted_dims.size() > 0) { int const i = sorted_dims[0]; tuple<int, box, box> splits = b.bisect_at(sorted_dims[0]); box const & first = get<1>(splits); box const & second = get<2>(splits); assert(first.get_idx_last_branched() == i); assert(second.get_idx_last_branched() == i); if (second.is_bisectable()) { box_stack.push_back(second); box_stack.push_back(first); } else { box_stack.push_back(first); box_stack.push_back(second); } if (config.nra_proof) { config.nra_proof_out << "[branched on " << b.get_name(i) << "]" << endl; } } else { config.nra_found_soln++; if (config.nra_multiple_soln > 1) { // If --multiple_soln is used output_solution(b, config, config.nra_found_soln); } if (config.nra_found_soln >= config.nra_multiple_soln) { break; } solns.push_back(b); } } } while (box_stack.size() > 0); ctc.set_used_constraints(used_constraints); if (config.nra_multiple_soln > 1 && solns.size() > 0) { return solns.back(); } else { assert(!b.is_empty() || box_stack.size() == 0); return b; } }
// free hash void free_hash(unordered_set<Structure*, hash_fncts, hash_eq> &structs) { unordered_set<Structure*, hash_fncts, hash_eq>::iterator it; for (it=structs.begin(); it!=structs.end(); it++) { //free((*it)->str); delete *it; } structs.clear(); }
///Reset object inline void reset() { filecontents = ""; if ( vpos != NULL ) delete [] vpos; patterns.clear(); categories.clear(); vcat.clear(); sizeofvpos = 0; ct = NULL; }
// free hash void free_hash(unordered_set<struct_en*, hash_fncts, hash_eq> &structs) { unordered_set<struct_en*, hash_fncts, hash_eq>::iterator it; for (it=structs.begin(); it!=structs.end(); it++) { free((*it)->structure); free(*it); } structs.clear(); }
void DFHack::EventManager::onStateChange(color_ostream& out, state_change_event event) { static bool doOnce = false; if ( !doOnce ) { //TODO: put this somewhere else doOnce = true; EventHandler buildingHandler(Buildings::updateBuildings, 100); DFHack::EventManager::registerListener(EventType::BUILDING, buildingHandler, NULL); //out.print("Registered listeners.\n %d", __LINE__); } if ( event == DFHack::SC_WORLD_UNLOADED ) { lastTick = 0; lastJobId = -1; for ( auto i = prevJobs.begin(); i != prevJobs.end(); i++ ) { Job::deleteJobStruct((*i).second); } prevJobs.clear(); tickQueue.clear(); livingUnits.clear(); nextItem = -1; nextBuilding = -1; buildings.clear(); constructions.clear(); Buildings::clearBuildings(out); gameLoaded = false; nextInvasion = -1; } else if ( event == DFHack::SC_WORLD_LOADED ) { uint32_t tick = DFHack::World::ReadCurrentYear()*ticksPerYear + DFHack::World::ReadCurrentTick(); multimap<uint32_t,EventHandler> newTickQueue; for ( auto i = tickQueue.begin(); i != tickQueue.end(); i++ ) { newTickQueue.insert(pair<uint32_t,EventHandler>(tick + (*i).first, (*i).second)); } tickQueue.clear(); tickQueue.insert(newTickQueue.begin(), newTickQueue.end()); nextItem = 0; nextBuilding = 0; lastTick = 0; nextInvasion = df::global::ui->invasions.next_id; gameLoaded = true; } }
int main() { int c = 0; size_t root, here; string s, a; while (true) { scanf("%zu", &n); if (!n) break; getchar(); sccSize.resize(n); fill(sccSize.begin(), sccSize.end(), 0); words.clear(); wordMapper.clear(); graph.clear(); revGraph.clear(); selectedWord.clear(); for (size_t i = 0; i < n; i++) { s.clear(); while ((c = getchar()) != 32 && c != 10) s.push_back(char(c)); root = insertWord(s); if (c == 10) continue; s.clear(); while ((c = getchar()) != 10) { if (c == 32) { if (s.empty()) continue; here = insertWord(s); s.clear(); graph[here].emplace_back(root); revGraph[root].emplace_back(here); } else s.push_back(char(c)); } if (!s.empty()) { here = insertWord(s); graph[here].emplace_back(root); revGraph[root].emplace_back(here); } } SCC(); sum = 0; for (size_t i = 0; i < n; i++) if (sccSize[i] > 0) reverseDFS(i); printf("%zu\n", sum); for (auto &v : wordMapper) { if (selectedWord.find(sccId[v.second]) != selectedWord.end()) printf("%s ", v.first.c_str()); } if (sum) puts(""); } }
bool Goblin::update( int key ) { int newx=x,newy=y; int tx=rand()%10+x-5,ty=rand()%10-5+y; checked.clear(); findPlayer(tx,ty,currentRoom,player->x,player->y); start: newx=x; newy=y; if(tx!=x && ty==y) goto mx; if(ty!=y && tx==x) goto my; if(ty!=y && tx!=x) if(rand()%2==0) goto mx; else goto my; goto end; mx: newx=x-sign(x-tx); if(moveTo(newx,newy)) return 0; if((newx!=x || newy!=y) && ty!=y) { newx=x; tx=x; goto my; } goto end; my: newy=y-sign(y-ty); if(moveTo(newx,newy)) return 0; if((newx!=x || newy!=y) && tx!=x) { newy=y; ty=y; goto mx; } goto end; end: if(newx!=x) { ty+=rand()%3-1; goto start; } if(newy!=y) { tx+=rand()%3-1; goto start; } return 0; }
void saneTest(unsigned iterations=1) { // Create index //cerr << "InitializeIndex()..." << flush; InitializeIndex(); //cerr << "done." << endl; // Reset nextDocId=1; nextQueryId=1; activeQueries.clear(); pendingResults.clear(); unsigned limit; for (unsigned i=0; i<iterations; ++i) { //cerr << "iteration " << i << endl; limit=rnd(1+(maxActiveQueries/100),maxActiveQueries); while (activeQueries.size() < limit) startQuery(); limit=rnd(1+(maxPendingResults/100),maxPendingResults); while (pendingResults.size() < limit) matchDocument(); while (pendingResults.size()) getNextAvailRes(); while (activeQueries.size()) endQuery(); maxActiveQueries*=2; maxPendingResults*=2; //cerr << endl; } //cerr << "\nDestroyIndex()..." << flush; // Destroy index DestroyIndex(); //cerr << "done." << endl; }
void DFSBT(int ans_limit) { for (int i = 0 ; i < map_n; i++) nodeQ[i].clear(); nodeQ[0].push_back(0); int first; exceptedmask.clear(); while (first < map_n && !succ_exit) { for (first = 0 ; first < map_n; first++) while (!nodeQ[i].empty()) { //recalc path, enterDFS(first,ans_limit); } } }
bool checkCol(vector<vector<char>> & board, unordered_set<char> & s, int col) { s.clear(); for (int i = 0; i < board.size(); i++) { if (board[i][col] >= '1' && board[i][col] <= '9') { if (s.find(board[i][col]) != s.end()) { return false; } else { s.insert(board[i][col]); } } } return true; }
int main() { ios_base::sync_with_stdio(false); bool first = true; int n; while (cin >> n) { if (first) first = false; else cout << '\n'; Buys buy_orders(buy_cmp); Sells sell_orders(sell_cmp); for (auto i = 1; i <= n; ++i) { string cmd; cin >> cmd; if (cmd[0] == 'B') process_incoming(buy_orders, sell_orders, i); else if (cmd[0] == 'S') process_incoming(sell_orders, buy_orders, i); else // cancel order { int ci; cin >> ci; if (!gone.count(ci)) { if (b_seq2iter.count(ci)) { auto &it = b_seq2iter[ci]; price2size[it->price] -= it->size; buy_orders.erase(it); } else { auto &it = s_seq2iter[ci]; price2size[it->price] -= it->size; sell_orders.erase(it); } gone.insert(ci); } } print_quote(buy_orders, sell_orders); } price2size.clear(); b_seq2iter.clear(); s_seq2iter.clear(); gone.clear(); } return 0; }
void killMe(unsigned iterations) { InitializeIndex(); // Reset nextDocId=1; nextQueryId=1; activeQueries.clear(); pendingResults.clear(); for (unsigned i=0; i<iterations; ++i) { unsigned op=r.next()%4; try { switch(op) { case 0: startQuery(); break; case 1: if (activeQueries.size()) matchDocument(); break; case 2: if (pendingResults.size()) getNextAvailRes(); break; case 3: if (activeQueries.size()) endQuery(); break; default: throw runtime_error("invalid op"); } } catch (const runtime_error& ex) { //cerr << "Kill Me caught an exception: " << ex.what() << endl; } } DestroyIndex(); }
bool checkSubbox(vector<vector<char>> & board, unordered_set<char> & s, int row, int col) { s.clear(); for (int i = 3 * row; i < 3 * row + 3; i++) { for (int j = 3 * col; j < 3 * col + 3; j++) { if (board[i][j] >= '1' && board[i][j] <= '9') { if (s.find(board[i][j]) != s.end()) { return false; } else { s.insert(board[i][j]); } } } } return true; }
void us_isect(unordered_set<int> &out, const unordered_set<int> &in1, const unordered_set<int> &in2) { out.clear(); if (in2.size() < in1.size()) { us_isect(out, in2, in1); return; } for (unordered_set<int>::const_iterator it = in1.begin(); it != in1.end(); ++it) { if (in2.find(*it) != in2.end()) out.insert(*it); } }
int main() { int t = 1, T; for (scanf("%d", &T); t <= T; t++) { printf("Case #%d: ", t); string s; cin >> s; int len = s.size(); vector<int> d(len); for (int i = 0; i < len; i++) d[i] = s[i] - '0'; int n = stoi(s); seen.clear(); go(n, d, len); printf("%d\n", (int)seen.size()); } return 0; }
pair<int, int> recurse(TreeNode* node, long long prev, long long next, int& frequency, unordered_set<int>& modes) { if (node == nullptr) { return {0, 0}; } const auto l = recurse(node->left, prev, node->val, frequency, modes); const auto r = recurse(node->right, node->val, next, frequency, modes); const int n = l.second + r.first + 1; if ((node->val != prev) && (node->val != next)) { if (frequency < n) { frequency = n; modes.clear(); } if (frequency == n) { modes.insert(node->val); } } return {(node->val == prev) ? n : l.first, (node->val == next) ? n : r.second}; }
DFhackCExport command_result plugin_enable(color_ostream& out, bool enable) { if ( enabled == enable ) return CR_OK; enabled = enable; EventManager::unregisterAll(plugin_self); clearDijkstra(); lastInvasionJob = lastInvasionDigger = -1; activeDigging = false; invaderJobs.clear(); if ( enabled ) { EventManager::EventHandler handler(newInvasionHandler, 1000); EventManager::registerListener(EventManager::EventType::INVASION, handler, plugin_self); findAndAssignInvasionJob(out, (void*)0); } return CR_OK; }
vector<vector<string>> findLadders(string start, string end, unordered_set<string> &dict) { this->start = start; dict.insert(end); cur_lev.insert(start); while(true) { if (cur_lev.empty()) break; cleardict(dict, cur_lev); next_lev.clear(); for (auto i = cur_lev.begin(); i != cur_lev.end(); i++) expand(dict, *i); if (next_lev.find(end) != next_lev.end()) { path.push_back(end); out(end); return res; } cur_lev = next_lev; } return res; }
int commit(PostgreSQLConnection &pg_conn, size_t &flushSize, const char *date) { Clock clock("Inserted", "rows"); if (!preparePGTable(pg_conn.connection(), DARK_SPACE_TARGETS_SCHEMA_NAME, date, DARK_SPACE_TARGETS_TABLE_SCHEMA)) { return -1; } PGBulkInserter pgBulkInserter(pg_conn.connection(), DARK_SPACE_TARGETS_SCHEMA_NAME, date, flushSize, "%d, %ud, %ud, %ud, %ud, " \ "%ud, %ud, %ud, %ud, %ud, %ud, %ud, %ud, " \ "%d, %Vud"); cout << "Updating PostgreSQL database with dark space targets" << endl; clock.start(); for (map <TwoWayHostPair, DarkSpaceTarget>::iterator darkSpaceTargetItr = darkSpaceTargets.begin(); darkSpaceTargetItr != darkSpaceTargets.end(); ++darkSpaceTargetItr) { if (darkSpaceTargetItr -> second.initiator == TEMPORARILY_UNKNOWN_INITIATOR) { darkSpaceTargetItr -> second.initiator = PERMANENTLY_UNKNOWN_INITIATOR; } if (!pgBulkInserter.insert(NULL, darkSpaceTargetItr -> first.protocol, darkSpaceTargetItr -> first.internalIP, darkSpaceTargetItr -> first.externalIP, darkSpaceTargetItr -> first.internalPort, darkSpaceTargetItr -> first.externalPort, darkSpaceTargetItr -> second.initiator, darkSpaceTargetItr -> second.numBytes, darkSpaceTargetItr -> second.numPackets, darkSpaceTargetItr -> second.minPacketSize, darkSpaceTargetItr -> second.maxPacketSize, darkSpaceTargetItr -> second.startTime, darkSpaceTargetItr -> second.endTime, mySharedState -> ipInformation -> getASN(darkSpaceTargetItr -> first.externalIP), mySharedState -> ipInformation -> getCountry(darkSpaceTargetItr -> first.externalIP), (void*)&(darkSpaceTargetItr -> second.content))) { return -1; } clock.incrementOperations(); } if (pgBulkInserter.size() && !pgBulkInserter.flush()) { return -1; } clock.stop(); darkSpaceSources.clear(); darkSpaceTargets.clear(); return clock.operations(); }
// Copies the QNAME field from an answer section and returns its size, taking // into account pointers. static uint16_t getName(string &name, const char *payload, const char *_name) { uint16_t nameLength = 0; // Copies non-pointer parts. while (*_name && !isPointer(_name)) { if (name.length() + *_name > 255) { return 0; } nameLength += *_name + 1; if (!getLabel(_name, name)) { return 0; } _name += *_name + 1; } // Follows any pointers that may exist and copies their contents. if (isPointer(_name)) { visitedPositions.clear(); nameLength += 2; while (isPointer(_name)) { visitedPositions.insert(_name); _name = payload + (ntohs(*(uint16_t*)_name) & 0x3fff); // Detects more than one visit to the same location in the packet, // which would result in an infinite loop. if (visitedPositions.find(_name) != visitedPositions.end()) { return 0; } while (*_name && !isPointer(_name)) { if (name.length() + *_name > 255) { return 0; } if (!getLabel(_name, name)) { return 0; } _name += *_name + 1; } } } else { if (nameLength > 2) { ++nameLength; } } return nameLength; }
int get_ans(long long s) { vst.clear(); if (dpth.count(s)) return dpth[s]; queue<long long> q; q.push(s); vst.insert(s); int level = 0, sz, i, j; while (!q.empty()) { sz = q.size(); for (i = 0; i < sz; ++i) { long long node = q.front(); q.pop(); long long move[] = {get_next(l, node, true), get_next(r, node, true), get_next(all, node, true), get_next(l, node, false), get_next(r, node, false), get_next(all, node, false)}; for (j = 0; j < 6; ++j) if (dpth.count(move[j])) return level + 1 + dpth[move[j]]; for (j = 0; j < 6; ++j) if (vst.find(move[j]) == vst.end()) vst.insert(move[j]), q.push(move[j]); } ++level; } }
int main() { ios::sync_with_stdio(false); string str; while(cin >> str) { vec.clear(); isLinked.clear(); pathSet.clear(); isInvalid = false; process_str(str); while(cin >> str, str != "()") process_str(str); sort(vec.begin(), vec.end(), [](strI a, strI b) // lambda function. { return ((a.first.length() == b.first.length())? (a.first < b.first) : (a.first.length() < b.first.length())); } ); if(isInvalid || !isValidTree()) { cout << "not complete\n"; continue; } int sz = vec.size(); cout << vec[0].second; for(int i = 1; i < sz; ++i) cout << ' ' << vec[i].second; cout << '\n'; } return 0; }