anyone interested to discuss about the last question in ACM this year? <Tunnels
登录 | 论坛导航 -> 华新鲜事 -> 求学狮城 | 本帖共有 20 楼,分 1 页, 当前显示第 1 页 : 本帖树形列表 : 刷新 : 返回上一页
<<始页  [1]  末页>>
作者:chancing (等级:3 - 略知一二,发帖:750) 发表:2007-09-06 09:59:05  楼主  关注此帖评分:
anyone interested to discuss about the last question in ACM this year? <Tunnels

团结努力,不怕牺牲,排除万难.
我们要发达.
 

欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:icky (等级:15 - 最接近神,发帖:7923) 发表:2007-09-06 12:33:18  2楼
min-cut problem?
please initiate the discussion, then everyone follows.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:icky (等级:15 - 最接近神,发帖:7923) 发表:2007-09-07 18:16:24  3楼 评分:
construct a graph as follows
vertices: from 0 to n, n+1 vertices, where 0 is outside

edges: weight of edge = number of tunnel connecting the two vertices

perform standard max-flow algorithm

is that right?
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:icky (等级:15 - 最接近神,发帖:7923) 发表:2007-09-07 18:17:08  4楼
construct a graph as followsvertices: from 0 to n, n+1 vertices, where 0 is outside edges: weight of edge = number of tunnel connecting the two vertices perform standard max-flow algorithm is that right?
maxflow from vertex 0 to vertex 1
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:吴永铮 (等级:8 - 融会贯通,发帖:2078) 发表:2007-09-12 15:07:53  5楼
construct a graph as followsvertices: from 0 to n, n+1 vertices, where 0 is outside edges: weight of edge = number of tunnel connecting the two vertices perform standard max-flow algorithm is that right?
agree
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:bugzzj (等级:2 - 初出茅庐,发帖:13) 发表:2007-09-20 15:35:51  6楼 评分:
construct a graph as followsvertices: from 0 to n, n+1 vertices, where 0 is outside edges: weight of edge = number of tunnel connecting the two vertices perform standard max-flow algorithm is that right?
disagree
Let the edges being:
1 2
2 0
1 3
3 0
1 4
4 0

is the max-flow 3? if true, then disagree since we can wait until the spy enter one of 2, 3 or 4.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:吴永铮 (等级:8 - 融会贯通,发帖:2078) 发表:2007-09-20 16:25:48  7楼 评分:
disagreeLet the edges being: 1 2 2 0 1 3 3 0 1 4 4 0 is the max-flow 3? if true, then disagree since we can wait until the spy enter one of 2, 3 or 4.
opps! you are right.
The tunnel can be bombed at any time.

I didn't read the question carefully.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:房间 (等级:2 - 初出茅庐,发帖:21) 发表:2007-09-20 21:03:55  8楼 评分:
这样可以么?
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  9楼 评分:
这样可以么?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版只看此人从这里展开收起列表
作者:bugzzj (等级:2 - 初出茅庐,发帖:13) 发表:2007-09-21 10:29:07  10楼 评分:
这样可以么?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
似乎还是不行
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, 然后等一下。可以更好一些。
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:房间 (等级:2 - 初出茅庐,发帖:21) 发表:2007-09-21 11:32:50  11楼
似乎还是不行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  12楼
是可以的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  13楼
看错了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版只看此人从这里展开收起列表
作者:bugzzj (等级:2 - 初出茅庐,发帖:13) 发表:2007-09-24 14:50:06  14楼
顺带询问一个问题是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.
如果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)吧。
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:icky (等级:15 - 最接近神,发帖:7923) 发表:2007-09-24 16:14:14  15楼
disagreeLet the edges being: 1 2 2 0 1 3 3 0 1 4 4 0 is the max-flow 3? if true, then disagree since we can wait until the spy enter one of 2, 3 or 4.
so assume the spy enters 2
u then destroy the tunnel from 2 to 0, he can still go back to 1, and choose aon of 3 or 4
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:icky (等级:15 - 最接近神,发帖:7923) 发表:2007-09-24 16:14:31  16楼
so assume the spy enters 2u then destroy the tunnel from 2 to 0, he can still go back to 1, and choose aon of 3 or 4
choose one of 3 or 4
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:bugzzj (等级:2 - 初出茅庐,发帖:13) 发表:2007-09-24 17:21:54  17楼
so assume the spy enters 2u then destroy the tunnel from 2 to 0, he can still go back to 1, and choose aon of 3 or 4
i think we can destroy the tunnels 2 0 and 2 1 simultaneously.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:icky (等级:15 - 最接近神,发帖:7923) 发表:2007-09-25 09:49:24  18楼
i think we can destroy the tunnels 2 0 and 2 1 simultaneously.
ok, i misunderstood the problem
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:房间 (等级:2 - 初出茅庐,发帖:21) 发表:2007-10-16 01:02:38  19楼
如果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  20楼
这样可以么?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版只看此人从这里展开收起列表
论坛导航 -> 华新鲜事 -> 求学狮城 | 返回上一页 | 本主题共有 20 篇文章,分 1 页, 当前显示第 1 页 | 回到顶部
<<始页  [1]  末页>>

请登录后回复:帐号   密码