并查集.... E. Information Graph time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the…
Information Graph 把询问离线之后就能随便搞了, 去check一下是不是祖先, 可以用倍增也能用dfs序. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int…
Connected Graph Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3156 Accepted: 1533 Description An undirected graph is a set V of vertices and a set of E∈{V*V} edges.An undirected graph is connected if and only if for every pair (u,v)…
Clone Graph题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/clone-graph/description/ Description 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 uni…
题目: Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. How we serialize an undirected graph: Nodes are labeled uniquely. We use # as a separator for each node, and , as a separator for node label and each…
Complete The Graph 题解: 比较特殊的dij的题目. dis[x][y] 代表的是用了x条特殊边, y点的距离是多少. 然后我们通过dij更新dis数组. 然后在跑的时候,把特殊边都先当做1在跑,并且经过特殊边的时候,记得将x更新. 然后如果dis[0][t] < L 则代表不用特殊边也会小于L.所以无论是特殊的边答案是多少,dis[0][t]<L也是固定的. 然后我们不断检查dis[c][t] (for c 1 to N) 是不是 <= L . 找到对应的dis[c]…