예제 #1
0
파일: 2sat.cpp 프로젝트: dimakuz/ICPC2014
	void dfsr(size_t from) {
		visited[from] = false;
		solution[from] = true;
		for (auto itr : alist_rev[from]) {
			if (visited[itr])
				dfsr(itr);
		}
	}
예제 #2
0
파일: sparse.c 프로젝트: rebeccak1/class
int reachr(sp_mat *G, sp_mat *B,int k, int *xik,int *pinv){
	int p, n, top, *Bp, *Bi, *Gp;
	n=G->ncols; Bp = B->Ap; Bi = B->Ai;Gp = G->Ap;
	printf("calling reachr");
	top = n;
	for (p=Bp[k];p<Bp[k+1];p++){ /* For each entry in the k'th column of B */
		if (!SPMARKED(Gp,Bi[p])){ /* If node is not marked... */
			dfsr(Bi[p],G,&top,xik,pinv); /* ...start a depth first search at this entry.*/
		}
	}
	for (p=top; p<n; p++) SPMARK(Gp, xik[p]);
	return top;
}
예제 #3
0
파일: 2sat.cpp 프로젝트: dimakuz/ICPC2014
	bool satisfiable() {
		for (size_t i = 1; i < size; i++)
			if (!visited[i])
				dfs(i);

		for (auto it = post_order.rbegin(); it != post_order.rend(); it++)
			if (visited[*it] && visited[not_(*it)])
				dfsr(*it);

		for (size_t i = 1; i <= atoms; i++)
			if (solution[i] && solution[not_(i)])
				return false;
		return true;
	}
예제 #4
0
파일: sparse.c 프로젝트: rebeccak1/class
void dfsr(int j, sp_mat *G, int *top, int *xik, int *pinv){
	int i, p, p1, p2, jnew, *Gp = G->Ap, *Gi=G->Ai;
	jnew = pinv[j];
	SPMARK(Gp,j);
	if (jnew>=0){	/*We should consider the jnew column.*/
		p1 = SPUNFLIP(Gp[jnew]); /*Get true column pointers of neighbours:*/
		p2 = SPUNFLIP(Gp[jnew+1]);
		for(p=p1; p<p2; p++){ /* Iterate over neighboors */
			i = Gi[p];
			if (!SPMARKED(Gp,i)){ /* If any unmarked neighboors are found... */
				dfsr(i,G,top,xik,pinv); /*... do depth first search from that node. */
			}
		}
	}
	xik[--(*top)] = j; /*Put column value on stack. */
}