博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[POJ 2763] Housewife Wind
阅读量:5276 次
发布时间:2019-06-14

本文共 4050 字,大约阅读时间需要 13 分钟。

Housewife Wind
 

Description

After their royal wedding, Jiajia and Wind hid away in XX Village, to enjoy their ordinary happy life. People in XX Village lived in beautiful huts. There are some pairs of huts connected by bidirectional roads. We say that huts in the same pair directly connected. XX Village is so special that we can reach any other huts starting from an arbitrary hut. If each road cannot be walked along twice, then the route between every pair is unique. 
Since Jiajia earned enough money, Wind became a housewife. Their children loved to go to other kids, then make a simple call to Wind: 'Mummy, take me home!' 
At different times, the time needed to walk along a road may be different. For example, Wind takes 5 minutes on a road normally, but may take 10 minutes if there is a lovely little dog to play with, or take 3 minutes if there is some unknown strange smell surrounding the road. 
Wind loves her children, so she would like to tell her children the exact time she will spend on the roads. Can you help her? 

Input

The first line contains three integers n, q, s. There are n huts in XX Village, q messages to process, and Wind is currently in hut s. n < 100001 , q < 100001. 
The following n-1 lines each contains three integers a, b and w. That means there is a road directly connecting hut a and b, time required is w. 1<=w<= 10000. 
The following q lines each is one of the following two types: 
Message A: 0 u 
A kid in hut u calls Wind. She should go to hut u from her current position. 
Message B: 1 i w 
The time required for i-th road is changed to w. Note that the time change will not happen when Wind is on her way. The changed can only happen when Wind is staying somewhere, waiting to take the next kid. 

Output

For each message A, print an integer X, the time required to take the next child.

Sample Input

3 3 11 2 12 3 20 21 2 30 3

Sample Output

13

树链剖分、、、

#include 
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define INF 0x7fffffff#define ll long long#define N 100010struct Edge2{ int a,b,c;}s[N<<1];struct Edge{ int to,next;}edge[N<<1];int head[N],tot;int num[N];int pos;int fa[N];int son[N];int p[N];int fp[N];int deep[N];int size[N];int top[N];int n,q,st;void init(){ tot=0; pos=1; memset(head,-1,sizeof(head)); memset(son,-1,sizeof(son));}void add(int x,int y){ edge[tot].to=y; edge[tot].next=head[x]; head[x]=tot++;}void dfs1(int now,int pre,int d){ deep[now]=d; fa[now]=pre; size[now]=1; for(int i=head[now];i!=-1;i=edge[i].next) { int next=edge[i].to; if(next!=pre) { dfs1(next,now,d+1); size[now]+=size[next]; if(son[now]==-1 || size[next]>size[son[now]]) { son[now]=next; } } }}void dfs2(int now,int tp){ top[now]=tp; p[now]=pos++; fp[p[now]]=now; if(son[now]==-1) return; dfs2(son[now],tp); for(int i=head[now];i!=-1;i=edge[i].next) { int next=edge[i].to; if(next!=son[now]&&next!=fa[now]) { dfs2(next,next); } }}int sum[N<<2];void pushup(int rt){ sum[rt]=sum[rt<<1]+sum[rt<<1|1];}void build(int l,int r,int rt){ if(l==r) { sum[rt]=num[fp[l]]; return; } int m=(l+r)>>1; build(l,m,rt<<1); build(m+1,r,rt<<1|1); pushup(rt);}void update(int l,int r,int rt,int pos,int val){ if(l==r) { sum[rt]=val; return; } int m=(l+r)>>1; if(pos<=m) update(l,m,rt<<1,pos,val); else update(m+1,r,rt<<1|1,pos,val); pushup(rt);}int query(int l,int r,int rt,int L,int R){ if(L==l && R==r) { return sum[rt]; } int m=(l+r)>>1; if(R<=m) return query(l,m,rt<<1,L,R); else if(L>m) return query(m+1,r,rt<<1|1,L,R); else return query(l,m,rt<<1,L,m)+query(m+1,r,rt<<1|1,m+1,R);}int convert(int pos){ int a=s[pos].a; int b=s[pos].b; if(deep[a]>deep[b]) return a; return b;}void pre_solve(){ memset(num,-1,sizeof(num)); for(int i=1;i
deep[y]) swap(x,y); ans+=query(1,n,1,p[x]+1,p[y]); return ans;}int main(){ while(scanf("%d%d%d",&n,&q,&st)!=EOF) { init(); for(int i=1;i
a的最短路 { scanf("%d",&a); //cout<<"st-->a:"<
<<' '<
<

 

转载于:https://www.cnblogs.com/hate13/p/4118581.html

你可能感兴趣的文章
android:scaleType属性
查看>>
shell脚本
查看>>
Upload Image to .NET Core 2.1 API
查看>>
【雷电】源代码分析(二)-- 进入游戏攻击
查看>>
Linux中防火墙centos
查看>>
如何设置映射网络驱动器的具体步骤和方法
查看>>
centos下同时启动多个tomcat
查看>>
Leetcode Balanced Binary Tree
查看>>
[JS]递归对象或数组
查看>>
linux sed命令
查看>>
湖南多校对抗赛(2015.03.28) H SG Value
查看>>
hdu1255扫描线计算覆盖两次面积
查看>>
hdu1565 用搜索代替枚举找可能状态或者轮廓线解(较优),参考poj2411
查看>>
程序存储问题
查看>>
优雅地书写回调——Promise
查看>>
AX 2009 Grid控件下多选行
查看>>
PHP的配置
查看>>
Struts框架----进度1
查看>>
Round B APAC Test 2017
查看>>
MySQL 字符编码问题详细解释
查看>>