Example #1
0
File: main.cpp Project: riteme/test
int main() {
    initialize();

    for (int cnt = 0; cnt < t; cnt++) {
        scanf("%d", &n);

        eqcnt = noteqcnt = xcnt = 0;
        hashmap.clear();
        hashmap.reserve(SIZEMAX);
        make_set(SIZEMAX);
        flag = true;

        for (int opcnt = 0; opcnt < n; opcnt++) {
            int i, j, e;
            scanf("%d %d %d", &i, &j, &e);

            switch (e) {
                case 1:
                    eq[eqcnt].i = i;
                    eq[eqcnt].j = j;

                    if (hashmap.count(i) == 0) hashmap[i] = xcnt++;
                    if (hashmap.count(j) == 0) hashmap[j] = xcnt++;

                    union_set(hashmap[i], hashmap[j]);

                    eqcnt++;
                    break;
                case 0:
                    if (i == j) flag = false;

                    if (flag) {
                        noteq[noteqcnt].i = i;
                        noteq[noteqcnt].j = j;

                        noteqcnt++;
                    }
                    break;
            }  // switch to e
        }      // for

        for (int i = 0; i < noteqcnt and flag; i++) {
            Query &q = noteq[i];

            if (hashmap.count(q.i) > 0 and hashmap.count(q.j) > 0 and
                find_set(hashmap[q.i]) == find_set(hashmap[q.j]))
                flag = false;
        }  // for

        if (flag)
            printf(YES "\n");
        else
            printf(NO "\n");
    }  // for

    quit();
    return 0;
}  // function main
 WordDistance(vector<string>& words) {
   db.reserve(words.size());
   for(int i=0;i<words.size();i++){
     if(db.count(words[i])) { 
       db[words[i]].push_back(i); 
     } else {
       db[words[i]] = vector<int>{i};
     }
   }
 }
Example #3
0
void read(ifstream& fin, unordered_map<string, double>& imMap)
{
	size_t imNum;
	fin.read((char *)&imNum, sizeof(size_t));

	imMap.clear();
	imMap.reserve(imNum);
	for (size_t i = 0; i < imNum; i++)
	{
		string imName;
		read(fin, imName);
		imMap.insert(make_pair<string, double>(move(imName), 0));
	}
}
 WordDistance2(vector<string>& words) {
   result.reserve(2*words.size());
   string p;
   for(int i=0;i<words.size()-1;i++){ 
     for(int j=i+1;j<words.size();j++){
       if(words[i]==words[j]) continue;
       p = (words[i]>words[j]) ? (words[j]+"_"+words[i]) : (words[i]+"_"+words[j]);
       if(result.count(p)) {
         result[p] = min(result[p], j-i);
       } else { 
         result[p] = j-i;
       }
     }
   }
 }
Example #5
0
int main()
{
	known_cycles.reserve(1000000);
	known_cycles[1] = 1;

	unsigned i(0), j(0);
	while (cin >> i >> j)
	{
		if (!i || !j)
			break;
		auto n = FindMax(i, j);
		cout << i << " " << j << " " << n << endl;
	}
	return 0;
}
Example #6
0
void PostingList::GetLocationMap(domain_t domain, unordered_map<int64_t, unordered_set<length_t>> &output) const {
    auto entry = datamap.find(domain);

    if (entry == datamap.end())
        return;

    output.reserve(entry->second.size() / kEntrySize);

    const char *bytes = entry->second.data();
    for (size_t i = 0; i < entry->second.size(); i += kEntrySize) {
        int64_t location = ReadInt64(bytes, i);
        length_t offset = ReadUInt16(bytes, i + 8);

        output[location].insert(offset);
    }
}
Example #7
0
void initialize_dict(const char * file, unordered_map<string, unordered_set<int>> & index_dict, vector<string> & dict)
{
  index_dict.reserve(10000);
  ifstream ifs(file);
  if (ifs.is_open())
  {
    while (ifs.good())
    {
      string line;
      getline(ifs, line);
      dict.push_back(line);
      istringstream iss(line);

      string word;
      int index = dict.size() - 1;
      for (auto i = istream_iterator<string>(iss); i != istream_iterator<string>(); i++)
      {
        index_dict[*i].insert(index);
      }
    }
  }
}