Example #1
0
int main(){
    
    
    int rel_num;
    int m, n;
    int testcase = 0;
    scanf("%d%d",&n,&m);
    while(m!=0 || n!= 0){
        testcase++;
        rel_num = n;
        for(int i=1; i<=n; i++){
            p[i] = -1;
            size[i] = 1;
        }
        
        for(int i=0; i<m; i++){
            int rel_i, rel_j;
            scanf("%d%d", &rel_i, &rel_j);
            if (p[rel_i] == -1){
                if(p[rel_j] == -1){
                    p[rel_i] = rel_i;
                    p[rel_j] = rel_i;
                    size[rel_i]++;
                }
                else{
                    p[rel_i] = rel_j;
                     size[rel_j]++;
                }
                
            }
            else {
                if(p[rel_j] == -1){
                    p[rel_j] = rel_i;
                    size[rel_i]++;
                }
                else{
                    if(get_p(rel_i) == get_p(rel_j)){
                        continue;
                    }
                    
                    get_union(rel_i, rel_j);
                }
                
            }
            rel_num--;
            
            if(rel_i == rel_j)
                rel_num++;
        }
            
        printf("Case %d: %d\n", testcase, rel_num);
        
        scanf("%d%d",&n,&m);
        
    }
    
    return 0;
}
Example #2
0
	variant_type_ptr null_excluded() const {
		std::vector<variant_type_ptr> new_types;
		foreach(variant_type_ptr t, types_) {
			if(t->is_type(variant::VARIANT_TYPE_NULL) == false) {
				new_types.push_back(t);
			}
		}

		if(new_types.size() != types_.size()) {
			return get_union(new_types);
		} else {
			return variant_type_ptr();
		}
	}
bool hqend_hqstart_search_index::do_check_hqend_hqstart_ge(std::string &key, std::string &value, std::set<std::string> & search)
{
    float end = 0;
    std::multimap<float, std::string>::iterator it_le, it_ge, it;
    std::map<std::string, std::multimap<float, std::string> >  * search_index = current();
    SETS_OP_TRPE tmp_ot;
    proc_data* p_data = proc_data::instance();

    std::vector<std::string> tmp_vec;
    std::vector<std::set<std::string> > tmp_res_vec;

    if (strstr(key.c_str(), "|")) 
    {
        SplitString(value.c_str(), '|', &tmp_vec, SPLIT_MODE_ALL);
        tmp_ot = SETS_OP_UNION;
    }
    else 
    {
        SplitString(value.c_str(), '&', &tmp_vec, SPLIT_MODE_ALL); 
        tmp_ot = SETS_OP_INTERSECTION;
    }

    if (!tmp_vec.size())
        tmp_vec.push_back(value);

    for (uint32_t i = 0; i< tmp_vec.size(); i++)
    {
        std::vector<std::string> t_vec;
        SplitString(tmp_vec[i].c_str(), ':', &t_vec, SPLIT_MODE_ALL);
        std::string date;
        std::set<std::string> t_res; 
        p_data->_hquoation_dict->current()->get_last_date(atoi(t_vec[0].c_str()), date);
        if (date.empty()) 
        { 
            tmp_res_vec.push_back(t_res);
            continue;
        }

        end = atof(t_vec[1].c_str());
        auto ii = search_index->find(date); 
        if (ii == search_index->end())
        {
            tmp_res_vec.push_back(t_res);
            continue;;
        }

        it_le = ii->second.end();
        it_ge = ii->second.begin();

        it_ge = ii->second.lower_bound(end);

        for (it = it_ge; it != it_le; ++it)
        {
            t_res.insert(it->second);
        }

        tmp_res_vec.push_back(t_res);
    }

    if (tmp_ot == SETS_OP_INTERSECTION)
        get_intersection(tmp_res_vec, search);
    else
        get_union(tmp_res_vec, search);

    return true;
}