Fire! -两次dfs】的更多相关文章

题目描述: Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe escape the maze. Given Joe’s location in the maze and which squares of the maze are on fire…
两次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…
树链剖分,顾名思义就是将树形的结构剖分成链,我们以此便于在链上操作 首先我们需要明白在树链剖分中的一些概念 重儿子:某节点所有儿子中子树最多的儿子 重链:有重儿子构成的链 dfs序:按重儿子优先遍历时的顺序 轻儿子的意思就与重儿子相反 首先是第一个dfs操作 在本次操作中,我们主要做的是处理所有节点的父亲,子树大小,重儿子,深度等操作 void dfs1(int now,int father,int deep) { tree[now].depth=deep;//初始化当前节点的深度,子树大小,父…
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cstring> #include <functional> #include <vector> using namespace std; + ; ; int n; bool used[maxn]; vector<int> G[maxn]…
[题目大意] 有n个材料,m个评委.每种材料可以被用来做满族菜或汉族菜,m个评委有两种可以让他满意的猜中.问是否可以满足所有评委要求? [思路] 每天只能做三道题,我已经是一个废人了……(葛优躺.jpg) 裸2-SAT,先写了个两遍DFS的,速度略慢……24ms? #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> u…
题目链接:http://poj.org/problem?id=1481 两次DFS,这里的思路是,没找到*,就说明,有一个骰子,因此,每搜索到一个*,深搜4个方向,并且变为'.',要是搜到'X',就是骰子的点数++,而且将他的四周的'X'变为'.' #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> #include<…
黑科技--树剖两次\(dfs\)转一次\(dfs\)! 重所周知,树链剖分通常是要\(dfs​\)两次的,就像这样: int Fa[N],dep[N],Sz[N],son[N]; void dfs1(int x,int pre){ Fa[x]=pre,dep[x]=dep[pre]+1; Sz[x]=1; erep(i,G,x){ int y=G.to[i]; if(y==pre)continue; dfs(y,x); Sz[x]+=Sz[y]; (Sz[y]>Sz[son[x]])&&am…
Fire Net Time Limit: 2 Seconds      Memory Limit: 65536 KB Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall. A blockhouse is a small c…
Fire Net Problem Description Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall. A blockhouse is a small castle that has four openings t…
Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 14780    Accepted Submission(s): 8932 Problem Description Suppose that we have a square city with straight streets. A map of a city is a…