随笔分类 - Graph Theory
Nice nice nice……
摘要:题目:Park Visit原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4607分析:求树的直径。所谓树的直径,指的是一棵树里任意两点之间的最远距离。方法为选定一点,然后从该点bfs,则最后一个出栈的点必为直径的一端,然后以该点为起点bfs,求出直径即可。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 #define maxn 10000510 int T,n,m;11 vectorg[ma
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2722分析:简单最短路,读入数据烦。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #define maxn 450 9 #define inf 0xfffffff10 using namespace std;11 int blip[maxn];12 int n,m;13 bool vis[maxn];14 struct edge15 {16 int to,w;17 edg...
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2363分析:最短路+二分。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #define ll long long 10 #define maxn 105 11 #define inf 0x7fffffff 12 using namespace std; 13 int T,n,m,low,up; 14 int h[maxn],map[maxn][ma...
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2962分析:最短路+二分。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #define ll long long11 #define inf 100000000012 #define maxn 100513 using namespace std;14 struct edge15 {16 int to,h,len;17 edg...
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217分析:floyd. 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #define ll long long11 #define maxn 3312 #define inf 0xfffffff13 using namespace std;14 int n;char cur[30];15 mapm;16 double mapp[maxn][ma
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1142分析:最短路+记忆化搜索。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #define ll long long 9 #define inf 0x6fffffff10 #define maxn 100511 using namespace std;12 struct edge13 {14 int to,time;15 edge(int x,int y)16 ...
阅读全文
摘要:原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1874分析:SPFA|Dijkastra. 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #define ll long long 9 #define inf 0x6fffffff10 #define maxn 20511 using namespace std;12 int g[maxn][maxn],dis[maxn],n,m;13 bool vis[maxn];14 void dij
阅读全文
摘要:原题连接:http://acm.hdu.edu.cn/showproblem.php?pid=2066分析:超级源点+SPFA。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #define ll long long 9 #define inf 0xfffffff10 #define maxn 100511 using namespace std;12 struct edge13 {14 int to,time;15 edge (int x,int y)16 ...
阅读全文

浙公网安备 33010602011771号