Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:dfs之,加个 剪枝即可

Posted by schindlerlee at 2009-09-09 01:47:06 on Problem 2132
In Reply To:这题怎么做啊。。没有思路。。 Posted by:Acsaga at 2007-07-26 01:07:24
void dfs(int u, int w)
{
	if (u == 2) {
		res = lcm(res, w);
		return;
	}
	if (res % w == 0) //重要剪枝
		return;
	for (L * tmp = adj[u].next; tmp; tmp = tmp->next) {
		if (vis[tmp->v] == 0) {
			LL g = gcd(w, tmp->w);
			vis[tmp->v] = 1;
			if (g > 1 && res % g != 0) {
				dfs(tmp->v,g);
			}
			vis[tmp->v] = 0;
		}
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator