void* gencthreadfunc(void* thearg){ gencstruct* arg=(gencstruct*)thearg; gencreturnstruct* ret=&arg->ret; aprioriset tset; aprioriset* pset=&tset; int i, j=0, k, flag, ccount=0; ret->num=0; for(i=arg->num;i<arg->l->num;i++){ flag=0; if(numofmatch(&arg->l->valuelist[i], arg->s)==arg->length-1){ mergeset(pset, &arg->l->valuelist[i], arg->s); pset->length=arg->length+1; for(k=0;k<j;k++){ if(isequal(pset, &ret->valuelist[k])){ flag=1; break; } } if(flag){ deleteaprioriset(&pset); } else{ ret->valuelist[j]=*pset; ret->proper[j]=isproper(&ret->valuelist[j], arg->l); ret->num++; j++; } } } }
void Solve::solve(FILE *fin, FILE *fout) { fscanf(fin, "%d%d%d", &nVtx, &nEdge, &nQuery); for(int i = 0; i < nVtx; i ++) mkset(i); for(int i = 0; i < nEdge; i ++) fscanf(fin, "%d%d%d", &edge[i].u, &edge[i].v, &edge[i].w); std::sort(edge, edge + nEdge); for(int i = 0; i < nQuery; i ++) { query[i].idx = i; fscanf(fin, "%d", &query[i].val); } std::sort(query, query + nQuery); int edgeIt = 0; Val_t ansCnt = 0; for(int i = 0; i < nQuery; i ++) { while(edgeIt < nEdge && edge[edgeIt].w <= query[i].val) { int u = edge[edgeIt].u - 1, v = edge[edgeIt].v - 1; int p = findset(u); int q = findset(v); if(p != q) { ansCnt += cnt[p] * cnt[q]; mergeset(p, q); } edgeIt ++; } ans[query[i].idx] = ansCnt; } for(int i = 0; i < nQuery; i ++) fprintf(fout, VAL_T_FMT "\n", ans[i]); }