摘要: 题意:输入一个有向图,判断该图是否是有向无环图(Directed Acyclic Graph)。解法:还是深搜 1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 bool paths[101][101]; 8 int visited[101]; 9 bool isDAG;10 int vertices,edges;11 12 void DFS(int current){13 for(int j =1; isDAG == true && j > vertices >> edges;31 f 阅读全文
posted @ 2014-01-13 21:31 shaoshuai1990 阅读(301) 评论(0) 推荐(0) 编辑
摘要: 题意:输入一个简单(无多重边和自环)的连通无向图,判断该图是否能用黑白两种颜色对顶点染色,使得每条边的两个端点为不同颜色.解法:由于无自连通节点存在,所以只需进行一次宽搜,遍历所有的点和所有的边,判断能否用两种颜色进行染色即可!宽搜时对访问点需要进行颜色判断和标记! 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int colors[1001]; 7 bool paths[1001][1001]; 8 int main(){ 9 int vertices,edges;10 int from,dest;1... 阅读全文
posted @ 2014-01-13 16:42 shaoshuai1990 阅读(247) 评论(0) 推荐(0) 编辑