题目链接: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. 微软职位内部推荐-Enterprise Architect - BDE - BJ

    微软近期Open的职位: Enterprise ArchitectCloud, HTML5, Big Data and Mobile are technology trends driving pro ...

  2. OpenWrt刷机后LAN口无法连通的问题

    [路由器开发板硬件固件配置] MTK双频:MT7620a + MT7612e 内存:256 MB 闪存:16 MB 固件:MTK自带SDK中的OpenWrt固件(mtksdk-openwrt-2.6. ...

  3. Halcon学习笔记之缺陷检测(一)

    例程:surface_scratch.hdev 说明:这个程序利用局部阈值和形态学处理提取表面划痕 代码中绿色部分为个人理解和注释,其余为例程中原有代码 *surface_scratch.hdev:e ...

  4. maven学习心得整理

    maven的学习心得 已经接触了maven项目有一段时间了,开始时仅仅会使用,在使用中发现了它的强大和方便,于是决心研究一下: 首先,普及一下maven参数: -D:传入属性参数 -P:使用POM中指 ...

  5. Log4j XML配置

    问题描述:     Log4j  XML配置 问题解决:     (1)编写log4j.xml配置文件 注:     如上的XML文件必须以log4j.xml文件命名,否则无法读取配置文件,同样的如果 ...

  6. 【转载】struct和typedef struct彻底明白了

    分三块来讲述: 1 首先://注意在C和C++里不同 在C中定义一个结构体类型要用typedef: typedef struct Student { int a; }Stu; 于是在声明变量的时候就可 ...

  7. phonegap file操作

    phonegap中,有时候需要操作到手机中的文件,这个时候就需要用到phonegap官方提供的插件 file ,英文好的可以直接参考官方文档 首先是安装插件:(需要phonegap 3.0 以上,不止 ...

  8. Unity3D研究院之IOS全自动打包生成ipa

    接着上一篇文章, 自动生成framework,这篇文章我把shell自动化打包ipa整理了一下,希望大家喜欢,嘿嘿.. 建议大家先看一下上一篇文章.http://www.xuanyusong.com/ ...

  9. C#中sealed关键字

    C#中sealed关键字 1. sealed关键字     当对一个类应用 sealed 修饰符时,此修饰符会阻止其他类从该类继承.类似于Java中final关键字.     在下面的示例中,类 B ...

  10. Java Socket编程readLine返回null,read返回-1的条件

    客户端正常关闭socket的时候,服务器端的readLine()方法会返回null,或者read()方法会返回-1