Exemplo n.º 1
0
 void dfs(char c, int i,int j,int id,set<II>& S) {
   S.emplace(i,j);
   cid[i][j]=id;
   FORR(m,moves) {
     int i2=i+m.first,j2=j+m.second;
     if(i2<0||i2>=N||j2<0||j2>=N) continue;
     if(B[i2][j2]!=c) continue;
     if(cid[i2][j2]!=-1) continue;
     S.emplace(i2,j2);
     cid[i2][j2]=id;
     dfs(c,i2,j2,id,S);
   }
int main()
{
//    Open();
    int n, q;
    int cas = 0;
    while(~scanf("%d%d", &n,&q))
    {
        cas++;
        Tn = 0;
        tot = 0;
        for(int i = 0; i <= n; i++) G[i].clear();
        for(int i = 1; i < n; i++)
        {
            int u, v;
            scanf("%d%d", &u,&v);
            G[u].push_back(v);
            G[v].push_back(u);
        }
        dfs(1, -1, 0);
        dfsSeg(1, -1);

        int last = 0;
        while(q--)
        {
            int k, p, t;
            scanf("%d%d%d", &k, &p, &t);
            t--;
            S.clear();
            p += last;
            p = p%n+1;
            for(int i = 0; i < k; i++)
            {
                int x;
                scanf("%d", &x);
                bool flag = true;
                it = it1 = S.upper_bound(PII(st[x], 0));
                it2 = S.upper_bound(PII(ed[x], 0));
                if(it != S.begin()) it--;
                else flag = false;
                S.erase(it1, it2);
                if(!flag || !(it->first <= st[x] && it -> second >= ed[x]))
                    S.emplace(st[x], ed[x]);
            }
            int pre = 1;
            int ans = -1;
            for(it1 = S.begin(); it1 != S.end(); it1++)
            {
                int l = it1->first;
                if(pre < l) ans = res(ans, query(T[p], pre, l-1, t, 0), t);//, printf("%d, %d\n", pre, l-1);
                pre = it1->second + 1;
            }
            if(pre <= Tn) ans = res(ans, query(T[p], pre, Tn, t, 0), t);//, printf("%d, %d\n", pre, Tn);
            printf("%d\n", ans);
            last = max(ans, 0);
        }
    }
    return 0;
}
Exemplo n.º 3
0
 void loadWords(const string &input, set<dictTuple> &textWords) {
     ifstream fin(input);
     if (!fin.is_open()) {
         throw invalid_argument("File" + input + " Not Found");
     }
     cout << "Loading file: " + input << endl;
     string buf;
     regex e(wordRegex, regex_constants::extended);
     while (getline(fin, buf)) {
         smatch match;
         regex_search(buf, match, e);
         for (auto word:match) {
             string tmp(word.str());
             transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
             textWords.emplace(tmp, false);
         }
     }
     textWords.erase(dictTuple("", 0));
 }
Exemplo n.º 4
0
 int getId(TreeNode* p) {
     int ret;
     if (p == nullptr) {
         ret = -1;
     } else {
         pair<int, pair<int, int>> key;
         key.first = p->val;
         key.second.first = getId(p->left);
         key.second.second = getId(p->right);
         if (mp.count(key) > 0) {
             ret = mp[key];
         } else {
             ret = mp.size();
             mp[key] = ret;
         }
         // printf("%d => %d\n", p->val, ret);
     }
     ids.emplace(ret);
     return ret;
 }