摘要: /*题目: 有n种物品,现给出m种关系,每种关系a,b对应着物品b能够用物品a来换,然后有q个询问(a,b), 问物品a能不能换到物品b。分析: 如果直接dfs求传递闭包的话,会超时的。我们可以重新建图,使得图中没有环,即把强连通分支 变成缩点后用邻接表重新建图,然后dfs求传递闭包即可*/#include <cstdio>#include <vector>#include <cstring>#include <iostream>using namespace std;const int X = 5005;int dfn[X],father[X] 阅读全文
posted @ 2012-05-19 10:45 yejinru 阅读(239) 评论(0) 推荐(1) 编辑
摘要: /*找到强连通分量变成缩点后求给出出度为0的所有点以下用tarjan算法做,第一个是用结构体的邻接链表来做,第二个使用的是vector作为邻接链表*/#include <cstdio>#include <cstring>const int X = 15002;int dfn[X],low[X],stack[X],father[X],depth,top,bcnt;int counter[X],n,m;bool instack[X];struct node{ int v; node *next; void fun() { v = 0; next ... 阅读全文
posted @ 2012-05-19 09:03 yejinru 阅读(192) 评论(0) 推荐(0) 编辑