这样可以么?
登录 | 论坛导航 -> 华新鲜事 -> 求学狮城 | 本帖共有 7 楼,分 1 页, 当前显示第 1 页 : 本帖树形列表 : 刷新 : 返回上一页
<<始页  [1]  末页>>
作者:房间 (等级:2 - 初出茅庐,发帖:21) 发表:2007-09-20 21:03:55  楼主  关注此帖评分:
anyone interested to discuss about the last question in ACM this year? (more...)
这样可以么?
for each node v

perform a maximal flow between v and 0 to obtain the minimal cut (=mc);

set the key of v to mc and insert it into a Fibonacci heap h;

end

while(true)

v = h.extract_min(); (based on the key)

remove v and all edges incident on v;

if(node 1 is disconnected from node 0)

return v.key;

end
end
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
作者:房间 (等级:2 - 初出茅庐,发帖:21) 发表:2007-09-20 21:19:45  2楼 评分:
这样可以么?for each node v perform a maximal flow between v and 0 to obtain the minimal cut (=mc); set the key of v to mc and insert it into a Fibonacci heap h; end while(true) v = h.extract_min(); (based on the key) remove v and all edges incident on v; if(node 1 is disconnected from node 0) return v.key; end end
顺带询问一个问题
是CLRS page 216 10.4-5


Write an O(n)-time nonrecursive procedure that, given an n-node binary tree, prints out the key of each node. Use no more than constant extra space outside of the tree itself and do not modify the tree, even temporarily, during the procedure.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
作者:房间 (等级:2 - 初出茅庐,发帖:21) 发表:2007-09-21 11:32:50  3楼
似乎还是不行1 2 2 0 1 3 3 0 1 4 4 0 1 5 5 0 5 0 5 0 5 0 对min-cut不是很清楚,下面的计算对吗? MC(1)=4 MC(2)=2 MC(3)=2 MC(4)=2 MC(5)=5 如果是对的,根据你的算法,结果应该是MC(1)=4吧? 不过,先断掉edge 1 5, 然后等一下。可以更好一些。
是可以的
In your case:

MC(1) = 3;
MC(2) = 2;
MC(3) = 1;
MC(4) = 2;
MC(5) = 5;

min cut means the minimal number of cuts to disconnect the source node from the sink node, so for node 1, we only need to cut the following edges:
(1, 5), (2, 0), (4, 0). Of course there are some other minimal cuts.

Accoring to my algorithm, it will output 3.

According to what you have said, you want to first cut (1, 5), then the spy has only two paths to escape, namely, through node 2 and through node 4. For the path that bypasses node 2, you have to wait until the spy has entered room 2, then you need to cut (1, 2) and (2, 0), which incurs two cuts, so in total, it's three cuts. Similarly for the path through node 4.

If you cut (1, 5) in the first place, and then wait until the spy has entered room 2, and you only cut (2, 0), then the spy can turn back to choose the path that goes through node 4. So you still need to cut (1, 4) or (4, 0). In this case, you again need three cuts, which matches the output of my algorithm.

欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
作者:房间 (等级:2 - 初出茅庐,发帖:21) 发表:2007-09-21 11:38:19  4楼
是可以的In your case: MC(1) = 3; MC(2) = 2; MC(3) = 1; MC(4) = 2; MC(5) = 5; min cut means the minimal number of cuts to disconnect the source node from the sink node, so for node 1, we only need to cut the following edges: (1, 5), (2, 0), (4, 0). Of course there are some other minimal cuts. Accoring to my algorithm, it will output 3. According to what you have said, you want to first cut (1, 5), then the spy has only two paths to escape, namely, through node 2 and through node 4. For the path that bypasses node 2, you have to wait until the spy has entered room 2, then you need to cut (1, 2) and (2, 0), which incurs two cuts, so in total, it's three cuts. Similarly for the path through node 4. If you cut (1, 5) in the first place, and then wait until the spy has entered room 2, and you only cut (2, 0), then the spy can turn back to choose the path that goes through node 4. So you still need to cut (1, 4) or (4, 0). In this case, you again need three cuts, which matches the output of my algori
看错了
Sorry I overlooked the edge (3, 0) in your specification. So the min cuts of each node are indeed:

MC(1) = 4;
MC(2) = 2;
MC(3) = 2;
MC(4) = 2;
MC(5) = 5;
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
作者:房间 (等级:2 - 初出茅庐,发帖:21) 发表:2007-09-21 11:40:43  5楼
看错了Sorry I overlooked the edge (3, 0) in your specification. So the min cuts of each node are indeed: MC(1) = 4; MC(2) = 2; MC(3) = 2; MC(4) = 2; MC(5) = 5;
And
You are right. My algorithm does not work for your case.

Let me think about it further.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
作者:房间 (等级:2 - 初出茅庐,发帖:21) 发表:2007-10-16 01:02:38  6楼
如果child有到parent的ref的话。Let struct treeNode{ int id; treeNode *left; treeNode *right; treeNode *par; }; DFS(treeNode *root){ treeNode *cur=root; while (cur!=NULL){ printf("%d, ", cur->id); if (cur->left!=NULL){ cur=cur->left; } else if (cur->right!=NULL) cur=cur->right; else{ treeNode *par=cur->par; while (par!=NULL){ if (par->left==cur && par->right!=NULL){ cur=par->right; break; } cur=par; par=par->par; } if (par==NULL) cur=NULL; } } } 其实就是depth first, 应该是O(3n)=O(n)吧。
gr8.
When I was asking for the answer, I didn't presume there is a parent link in each node, though. However, I guess the parent link is necessary.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
作者:房间 (等级:2 - 初出茅庐,发帖:21) 发表:2007-10-16 01:15:55  7楼
这样可以么?for each node v perform a maximal flow between v and 0 to obtain the minimal cut (=mc); set the key of v to mc and insert it into a Fibonacci heap h; end while(true) v = h.extract_min(); (based on the key) remove v and all edges incident on v; if(node 1 is disconnected from node 0) return v.key; end end
I have revised the solution.
for each node, store a number which is initialized to be the number of edges incident on that node. For node 0 (which represents outside), the number is infinity. we denote the number as node.mc.


changed = true;
while(changed)
{
changed = false;
for_each(node n in the graph except node 0)
{
sort n's adjacent nodes based on mc (from large to small).
k = 0; k1 = 0; prev_node = null;
for_each(node adj_n in the sorted adjacent nodes n)
{
if(adj_n.mc + k < n.mc)
{
n.mc = k + adj_n.mc;
changed = true;
}
k1 += number of edges between adj_n and n;
if(prev_node.mc > adj_n.mc)
{
k = k1;
}
prev_node = adj_n;
}
}
}

return node1.mc;
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
论坛导航 -> 华新鲜事 -> 求学狮城 | 返回上一页 | 本主题共有 7 篇文章,分 1 页, 当前显示第 1 页 | 回到顶部
<<始页  [1]  末页>>

请登录后回复:帐号   密码