URAL 2030 Awesome Backup System
Awesome Backup System
Memory limit: 64 MB
- Copy all the information from computer v to all adjacent computers (i.e., to all computers directly connected to it by a cable) If computer v had xv bytes of information, then, after copying, all adjacent computers will have xv bytes of information more, while computer v will still have xv bytes of information.
- Output the current amount of information on computer v. Since this amount can grow very quickly, output the remainder of its division by the number 109 + 7.
For testing the ABS, you are asked to write a program for a quick processing of such requests.
Input
Output
Samples
input | output |
---|---|
4 |
1 |
2 |
1 |
对一棵树进行下列操作
1 v 将顶点v的邻接顶点的权值加上w[v]
2 v 查询顶点v的权值
哎,还是太弱了,这题不需要任何数据结构,只需要先将树转换成有根树,开一个标记数组add,add[v]表示给v的邻接顶点增加了add[v],在进行1操作的时候,直接将v的父亲加上v的权值,则查询的时候只有父亲对他有影响,加上父亲的add标记就行
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a
#define pb push_back
typedef long long ll;
using namespace std;
const int N = 1e5+;
const int M = +;
const int mod=1e9+;
int n,m,k,tot=,s,t,r;
vector<int>G[N];
ll A[N],add[N]; int p[N];
void dfs(int u,int fa)
{
p[u]=fa;
for(int i=; i<G[u].size(); i++)
{
int &v=G[u][i];
if(v!=fa&&v!=u)
{
dfs(v,u);
}
}
}
int main()
{
int n,m;
cin>>n;
for(int i=;i<=n;i++)cin>>A[i];
int u,v;
for(int i=;i<n;i++)
{
cin>>u>>v;
G[u].pb(v);
G[v].pb(u);
}
cin>>m;
memset(add,,sizeof add);
memset(p,,sizeof p);
dfs(,);
while(m--)
{
cin>>u>>v;
int x=p[v];
if(u==)
{
add[v]=(add[v]+A[v]+add[x])%mod;
A[x]=(A[x]+A[v]+add[x])%mod;
}
else cout<<(A[v]+add[x])%mod<<endl;
}
return ;
}
URAL 2030 Awesome Backup System的更多相关文章
- 图解Android - Zygote, System Server 启动分析
Init 是所有Linux程序的起点,而Zygote于Android,正如它的英文意思,是所有java程序的'孵化池'(玩过星际虫族的兄弟都晓得的).用ps 输出可以看到 >adb shell ...
- 图解Android - System Service 概论 和 Android GUI 系统
通过 图解Android - Binder 和 Service 一文中,我们已经分析了Binder 和 Service的工作原理.接下来,我们来简要分析Android 系统里面都有哪些重要的Servi ...
- VES Hand Book Contents
3...ABOUT THE VES4...Foreword 6...Chapter 1......Introduction6......Visual Effects and Special Effec ...
- malware analysis、Sandbox Principles、Design && Implementation
catalog . 引言 . sandbox introduction . Sandboxie . seccomp(short for secure computing mode): API级沙箱 . ...
- Azure SQL Database 时间点还原(Point in Time Restore)功能
微软中国TechNet 7 Oct 2014 9:17 PM Comments 0 Likes 原文地址:http://blogs.technet.com/b/azuretw/archive/20 ...
- Merkle Tree学习
/*最近在看Ethereum,其中一个重要的概念是Merkle Tree,以前从来没有听说过,所以查了些资料,学习了Merkle Tree的知识,因为接触时间不长,对Merkle Tree的理解也不是 ...
- Mac OS 终端常用命令【搜藏】
基础概念 OS X 采用的Unix文件系统,所有文件都挂在跟目录“ /” 下面,所以不在要有Windows 下的盘符概念.比如什么“C:”你在桌面上看到的硬盘都挂在 /Volumes 下.比如接上个叫 ...
- ubuntu mint 15 编译安装PHP开发环境
php 5.3.5(download zip) httpd 2.2.24(download zip) mysql: apt-get install mysql step 1: install mysq ...
- Facebook Architecture
Facebook Architecture Quora article a relatively old presentation on facebook architecture another I ...
随机推荐
- Problem B 队列
Description Two bored soldiers are playing card war. Their card deck consists of exactly n cards, nu ...
- Map学习
1.Query Operations(查询操作) int size();boolean isEmpty(); boolean containsKey(Object key);boolean conta ...
- Visual Studio 中的头文件、源文件和资源文件都是什么?有什么区别??
头文件:后缀为.h,主要是定义和声明之类的,比如类的定义,常量定义源文件:后缀.cpp,主要是实现之类的,比如类方法的实现资源文件主要是你用到的一些程序代码以外的东西,比如图片之类,或者菜单.工具栏之 ...
- [网络技术]网关 路由器 OSI
tracert 1.网关与路由 关键的区别:网关是这样一个网络节点:以两个不同协议搭建的网络可以通过它进行通信.路由器是这样一种设备:它能在计算机网络间收发数据包,同时创建一个覆盖网络(overlay ...
- 使用goldengate交付指定时间前的数据
在数据同步过程中,客户担心在源端误操作,比如truncate, drop, delete all等,在目标端也会立即同步,而无法挽救损失:因此,客户希望是目标端的数据比源端要慢一个时间点. 解决方案: ...
- C++ primer的第三章的主要内容
第三章主要介绍了C++中标准库类型.主要讲到string和vector类型.在string类型中,能够很方便的操作字符串,应该要注意的地方就是它的字符串中元素的位置的类型是:size_type类型的数 ...
- ACM - 概率、期望题目 小结(临时)
概率DP求期望大多数都是全期望公式的运用.主要思考状态空间的划分以及状态事件发生的概率.问题可以分为无环和有环两类.无环一类多数比较简单,可以通过迭代或者记忆化搜索完成.有环一类略复杂,可以通过假设方 ...
- kali linux karmetasploit配置
原理分析:http://www.freebuf.com/articles/77055.html 转官方说明:https://www.offensive-security.com/metasploit- ...
- 在php中需要用到的mysql数据库的简单操作
1.数据库连接 1.1用windows命令行链接数据库服务器 几个DOS命令 在DOS环境下命令后面没有分号,在MySQL环境下,命令后面有分号 进入盘符: 语法:盘符: 进入盘符下的某个文件夹 语法 ...
- ERP登录(八)
登录的存储过程: ALTER PROCEDURE [dbo].[UserLogin] @userid int output, @LoginName nvarchar(50), @Password nv ...