题目链接: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. iOS 10 因苹果健康导致闪退 crash-b

    如果在app中调用了苹果健康,iOS10中会出现闪退.控制台报出的原因是: Terminating app due to uncaught exception 'NSInvalidArgumentEx ...

  2. [搜片神器]使用C#实现DHT磁力搜索的BT种子后端管理程序+数据库设计(开源)

    谢谢园子朋友的支持,已经找到个VPS进行测试,国外的服务器:http://www.sosobta.com   大家可以给提点意见... 出售商业网站代码,万元起,非诚勿扰,谢谢. 联系h31h31 a ...

  3. anroid ndk编译ffmpeg 引用librtmp libx264

    Ffmpeg 无处不在,自然android系统少不了它,折腾了不少时间完成 ndk编译ffmpeg,生成so库中引用了外部库librtmp,libx264.条条大路通罗马, 也许还有别的更好的方法去完 ...

  4. 在云服务器搭建WordPress博客(三)安装WordPress

    WordPress的安装在Windows环境下非常简单. 安装前的准备 1.下载最新版的 WordPress,解压后,将WordPress文件夹里面的所有文件,上传到你的主机空间域名所绑定的根目录. ...

  5. 解决在ubuntu下requests 无法找到模块packages

    我明明用pip install requests安装成功了,但是依然报下面的错 错误1 requests.packages.urllib3.disable_warnings()AttributeErr ...

  6. Openmeeting 网页打开缓慢,视频卡的一个解决方法

    在初次安装完openmeeting以后,从浏览器打开后发现网页缓慢,视频有卡顿的现象. 原因:为openmeeting分配的内存太小. 解决方法: 找到根目录的red5.bat,打开后查找“set J ...

  7. Document Set 【一】

    概括介绍: Document Set 是SharePoint2010之后出现的一个新的Feature.这个Feature的主要目的是两个: 1,是帮助 User 以一个文件的管理方式管理一个文件集合. ...

  8. UVA 10720 Graph Construction 贪心+优先队列

    题目链接: 题目 Graph Construction Time limit: 3.000 seconds 问题描述 Graph is a collection of edges E and vert ...

  9. ?--Porg.springframework.beans.MethodInvocationException: Property 'username' threw exception; nested exception is java.lang.NullPointerException

    使用BoneCP作为连接池,在启动Tomcat报出以下异常: 一月 02, 2016 2:12:17 下午 org.apache.tomcat.util.digester.SetPropertiesR ...

  10. Lua 代码编写技巧

    1.克隆表 u = {unpack(table)} 一般克隆长度较小的表 2.判断表是否为空 if next(t) == nil then..  判断该表是否为空,包括t={}的情况 3.插入表 使用 ...