hdu 3974 Assign the task
来源:互联网 发布:线切割3b五角星编程 编辑:程序博客网 时间:2024/05/23 05:08
开始被吓到了,以为要用什么动态树什么高深的东东。。。后来想了想跟线段树蛮像。。再后来想了想,并查集就可以完全搞定了。
因为这是一棵树哈,所以你在每个节点里记录任务以及这个任务的时间。查询的时候查当前节点所有的父节点(包括它本身),找最迟更新的(也就是离查询最近的)那个任务即可。
少写了句更新,下午WAshi了 = =。。。
#include <map>#include <set>#include <queue>#include <stack>#include <math.h>#include <time.h>#include <stdio.h>#include <stdlib.h>#include <iostream>#include <limits.h>#include <string.h>#include <string>#include <algorithm>#define MID(x,y) ( ( x + y ) >> 1 )#define L(x) ( x << 1 )#define R(x) ( x << 1 | 1 )#define BUG puts("here!!!")#define STOP system("pause")using namespace std;const int MAX = 50010;struct NODE{int col, t;};NODE p[MAX];int pre[MAX];void init(){memset(pre, -1, sizeof(pre));}int main(){int ncases, n, u, v, m, x, col;char s[5];scanf("%d", &ncases);int ind = 1;while( ncases-- ){scanf("%d", &n);init();for(int i=0; i<n-1; i++){scanf("%d%d", &u, &v);pre[u] = v;}for(int i=1; i<=n; i++){p[i].col = -1;p[i].t = -1;}scanf("%d", &m);printf("Case #%d:\n",ind++);int T = 0;while( m-- ){scanf("%s", s);if( s[0] == 'T' ){scanf("%d%d", &x, &col);p[x].col = col;p[x].t = ++T;}else{scanf("%d", &x);col = p[x].col;int t = p[x].t;while( x != -1 ){if( p[x].t > t ){col = p[x].col;t = p[x].t;}x = pre[x];}printf("%d\n", col);}}}return 0;}
- hdu 3974 Assign the task
- hdu 3974 Assign the task
- hdu 3974 Assign the task
- HDU 3974 Assign the task
- HDU 3974 Assign the task
- hdu 3974 Assign the task
- hdu 3974 Assign the task
- Assign the task(hdu 3974)
- Assign the task HDU
- Assign the task HDU
- HDU 3974 Assign the task (线段树)
- HDU 3974 Assign the task(线段树)
- hdu 3974 Assign the task (线段树)
- HDU 3974——Assign the task
- HDU 3974 Assign the task (并查集改编)
- HDU 3974 Assign the task 并查集
- HDU 3974 Assign the task(并查集)
- hdu 3974 Assign the task 线段树(时间戳)
- Android新浪微博开发(四)主UI的完善
- TCP/IP Illustrated 笔记 CIDR
- 应用程序间通讯 - URL Scheme
- usb 端点解释
- 浅谈:Android下的external源代码目录
- hdu 3974 Assign the task
- 原生态Android操作介绍之一
- android中requestWindowFeature用法
- STL中erase()用法陷阱
- ZOJ1709 POJ1562 Oil Deposits,并查集
- ISE 约束文件的基本操作
- AXIS报文头SOAPHEADER认证
- 为 eclipse 的 hibernate 配置文件(*.hbm.xml)加上自动提示功能
- WKT字段解释