It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any other highways to keep the rest of…
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=513 终于开始接触图了,恩,开始接触DFS了,这道题就是求连通分量,比较简单. #include<iostream> #include<cstring> using namespace std; int m, n; //记录连通块的数量 ][]; ][]; void…
两次DFS求树直径方法见 这里. 这里的直径是指最长链包含的节点个数,而上一题是指最长链的路径权值之和,注意区分. K <= R: ans = K − 1; K > R: ans = R − 1 + ( K − R ) ∗ 2; #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace std; ; struct n…
UVA 572 DFS(floodfill) 用DFS求连通块 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Description Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M…
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2189 Accepted Submission(s): 634 Problem Description When the magic ball game turns up, Kimi immediately falls in it. The int…
求连通分量 Sample Input2 //T5 3 //n m1 2// u v2 34 5 5 12 5 Sample Output24 # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <queue> # define LL long long using na…