题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3974

出现在窝bin的线段树专题里…第一时间想的是记录入度找出根节点,然后标记深度转换到线段树中。但是发现并不会这个姿势…于是直接深搜更新了…发现没有退化成链的数据。于是水水地过去了………………

 #include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; #define fr first
#define sc second
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f, sizeof(a)) #define lrt rt << 1
#define rrt rt << 1 | 1
const int maxn = ;
int n, m;
int in[maxn];
int depth[maxn];
bool vis[maxn];
vector<int> G[maxn];
int q[maxn], front, tail;
int task[maxn]; void bfs(int rt) {
front = tail = ;
int lv = ;
depth[rt] = lv++; q[tail++] = rt; vis[rt] = ;
while(front < tail) {
int u = q[front++];
Rep(i, G[u].size()) {
if(!vis[G[u][i]]) {
vis[G[u][i]] = ;
depth[G[u][i]] = lv;
q[tail++] = G[u][i];
}
}
lv++;
}
} void update(int rt, int p) {
task[rt] = p;
Rep(i, G[rt].size()) {
update(G[rt][i], p);
}
} int main() {
// FRead();
int T, _ = ;
Rint(T);
int u, v;
char cmd[];
while(T--) {
Rint(n);
Rep(i, n+) G[i].clear();
Cls(depth); Cls(vis); Cls(in); Clr(task, -);
Rep(i, n-) {
Rint(u); Rint(v);
G[v].push_back(u); in[u]++;
}
int rt = -;
For(i, , n+) if(!in[i]) rt = i;
bfs(rt);
Rint(m);
printf("Case #%d:\n", _++);
while(m--) {
Rs(cmd);
if(cmd[] == 'C') {
Rint(u);
printf("%d\n", task[u]);
}
if(cmd[] == 'T') {
Rint(u); Rint(v);
update(u, v);
}
}
}
return ;
}

[HDOJ3974]Assign the task(建树胡搞)的更多相关文章

  1. HDU 3974 Assign the task 暴力/线段树

    题目链接: 题目 Assign the task Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...

  2. [LeetCode]Integer Break(Dp或胡搞或推公式)

    343. Integer Break Given a positive integer n, break it into the sum of at least two positive intege ...

  3. HDU3974 Assign the task

    Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. HDU 3974 Assign the task(简单线段树)

    Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. HDU 3974 Assign the task 并查集/图论/线段树

    Assign the task Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  6. HDU 4690 EBCDIC (2013多校 1005题 胡搞题)

    EBCDIC Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total Su ...

  7. hdu 3874 Assign the task

    Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. J - Assign the task

    J - Assign the task HDU - 3974 思路:一眼秒思路<(* ̄▽ ̄*)/ dfs序+线段树. 通过dfs序把树上问题转化成线段上的问题.然后用线段树解决.    错因:都 ...

  9. 胡搞-强化版的light oj-1055-的思路-AI版的6重暴力For循环的BFS

    新题目大意: 三个棋子按照先后顺序,可以随意方向合法地走到空位置上(而不是像原题light oj-1055中的一样三个棋子每次走的方向都一致),当三个棋子全部走进目标地点,就结束:求需要指挥的最少次数 ...

随机推荐

  1. ZOJ 3229 有上下界最大流

    1: /** 2: ZOJ 3229 有上下界的最大流 3: 两次求最大流的过程,非二分 4: 有源汇上下界的最大流问题, 首先连接 sink -> src, [0,INF]. 5: 根据net ...

  2. cocos2dx中的坐标体系

    1.UI坐标系和GL坐标系 2.本地坐标与世界坐标 本地坐标是一个相对坐标,是相对于父节点或者你指明的某个节点的相对位置来说的,本地坐标的原点在参考节点的左下角 世界坐标是一个绝对的坐标,是以屏幕的左 ...

  3. SVN学习

    一.SVN在线安装(Eclipse) 步骤1: 步骤2 其中http://subclipse.tigris.org/update_1.10.x是最新版本的SVN插件的下载站点[subclipse是Ec ...

  4. 获取不到app.config里面的数据库连接字符串的解决方法

    今天在自己的类库里添加了对app.config文件的数据库连接字符串的引用,但是返回的居然是Null,纳闷了.然后在网上找到了答案原来是我的app.config文件加错了地方,应该加到启动项目里面,而 ...

  5. Oracle数据库表的备份和数据表的删除操作

    --Oracle数据库中的表备份: --备份语句:在备份之后就可以将这张表的所有数据源删除了,但是之后有人对这张表的数据进行操作,但是在操作完成之后要记得将数据表恢复 CREATE TABLE DZH ...

  6. MATLAB三维散点图的绘制(scatter3、plot3)

    MATLAB三维散点图的绘制(scatter3.plot3) (1)函数scatter3 用法:scatter3(x,y,z,'.',c) % c 为颜色,需和x,y,z长度相同 例子: x=[422 ...

  7. 【锋利的JQuery-学习笔记】添加提示图片

    效果图: hot图片: (注意:这个图标本身就有抖动效果的,并不是由于标签<del>而具有抖动效果) 周期性抖动,起到提示的作用 html: <div class="jnC ...

  8. Unity3D脚本中文系列教程(二)

    原地址:http://dong2008hong.blog.163.com/blog/static/469688272014030347910/ Unity3D脚本中文系列教程(一) .根据名称或标签定 ...

  9. Root resource classes

    Overview A root resource class is the entry point into a JAX-RS implemented RESTful Web service. It ...

  10. prim求MST

    PRIM==>>MST模板 #include <iostream> using namespace std; #define typec int #define V 3 con ...