题意:现有n个点m条边的无向图,每条边都有一种颜色,然后有q次询问,x y询问点x到点y共有几种颜色的边将他们连起来(不同颜色的边不能混在一起,要分开看)
思路:二维并查集,每种颜色维护一个并查集,查询时看某一种颜色下两个点是否有共同的father。...
分类:
其他好文 时间:
2015-03-29 18:08:21
阅读次数:
209
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for each node, and...
分类:
其他好文 时间:
2015-03-29 13:40:29
阅读次数:
109
题目地址:POJ 2553题目意思不好理解。题意是:G图中从v可达的全部点w,也都能够达到v,这种v称为sink。然后升序输出全部的sink。对于一个强连通分量来说,全部的点都符合这一条件,可是假设这个分量还连接其它分量的话,则肯定都不是sink。所以仅仅须要找出度为0的强连通分量就可以。代码例如以...
分类:
其他好文 时间:
2015-03-29 10:40:56
阅读次数:
127
int n,m;int first[maxn];int u[maxn],v[maxn],w[maxn],next[maxn];void read_graph(){ scanf("%d%d",&n,&m); for(int i=0;i<n;i++)first[i]=-1; for(i...
分类:
编程语言 时间:
2015-03-28 01:07:18
阅读次数:
137
算法的思想就不多说了。主要对代码解释一下。
graph = [[0,4,3,2],
[4,0,1,4],
[3,1,0,2],
[2,4,2,0]]
n = 4
flags = [True,True,True,True]
queue = []
#flags是存储节点访问情况的,true为待访问节点
#queue存储节点访问顺序
que...
分类:
编程语言 时间:
2015-03-27 22:28:04
阅读次数:
186
原题地址图的遍历,深度优先向来对图的数据结构就练习的比较少,这种题目还是挺好的。代码: 1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 bool dye(vector > &graph, vector &nodes...
分类:
其他好文 时间:
2015-03-22 00:29:12
阅读次数:
178
需要同时安装gnuplot和gnuplot-x11才能画出图sudo apt-get install gnuplot gnuplot-x11gnuplot not showing the graph window - Ask Ubuntu简单使用gnuplot>plot sin(x)
分类:
其他好文 时间:
2015-03-22 00:26:40
阅读次数:
140
Graph’s Cycle Component
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 2112 Accepted Submission(s): 775
Problem Description
In gra...
分类:
其他好文 时间:
2015-03-21 12:42:43
阅读次数:
143
1. Use BFS to search the graph.2. Create a hashtable to record the one to one mapping. 1 /** 2 * Definition for undirected graph. 3 * struct Undirec.....
分类:
其他好文 时间:
2015-03-19 06:19:16
阅读次数:
125
function Graph(v) { this.vertices = v; //初始化顶点 this.edges = 0; //边数先设置为0 this.adj = []; //为每一个顶点准备一个链表,表示它和所有节点的关系 for (var i = 0...
分类:
编程语言 时间:
2015-03-18 17:42:17
阅读次数:
377