URAL 2030 Awesome Backup System
2016-10-28 19:49
176 查看
![](https://images2015.cnblogs.com/blog/995422/201707/995422-20170724104434571-82564299.jpg)
Awesome Backup System
Time limit: 2.0 secondMemory limit: 64 MB
It is known that all people can be divided into two groups: those who have never lost important data and those who regularly perform data backups. Kirill is on his way from the first group to the second after the incident with tests described in the problem “Another Dress Rehearsal”. Not satisfied with the existing data backup solutions for various reasons, he decided to design his own backup system. He chose a simple but proud name for it: the “Awesome Backup System,” ABS for short. Since errors in such an important system are absolutely unacceptable, Kirill asks you to test the beta version of his product.
The ABS is organized as follows: let there be n computers in a local network. The computers are numbered with integers from 1 to n. Some pairs of computers are connected by cables. For economy, the network doesn’t have unnecessary cables, which means that there is a unique cable path between any two computers. Initially there are ai bytes of information written on the i-th computer. The ABS can process two types of requests:
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
The first line contains the number n of computers in the network (1 ≤ n ≤ 105). In the second line you are given integers a1, …, an, which are the amounts of information (in bytes) on the computers at the initial time (0 ≤ ai ≤ 109). Each of the following n − 1 lines contains integers x and y (1 ≤ x, y ≤ n; x ≠ y), which mean that the computers with numbers x and y are connected by a cable. It is guaranteed that the network is connected.The next line contains the number m of requests to the system (1 ≤ m ≤ 105). In the following m lines you are given the requests in the order of their execution. Each request is a pair of integers t and v (1 ≤ t ≤ 2 and 1 ≤ v ≤ n), where t specifies the type of the request and v is the number of the computer to which the request is applied.
Output
For each request of the second type, output in a separate line the remainder of the division of the answer by the number 109 + 7.Samples
input | output |
---|---|
4 1 1 1 1 1 2 1 3 2 4 9 2 1 2 2 2 3 2 4 1 1 2 1 2 2 2 3 2 4 | 1 1 1 1 1 2 2 1 |
2 1 1 1 2 14 2 2 2 1 1 1 2 2 1 2 2 1 1 1 2 2 1 2 2 1 1 1 2 2 1 2 2 1 | 1 1 2 3 5 8 13 21 |
对一棵树进行下列操作
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+10; const int M = 124750+10; const int mod=1e9+7; int n,m,k,tot=0,s,t,r; vector<int>G ; ll A ,add ; int p ; void dfs(int u,int fa) { p[u]=fa; for(int i=0; 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=1;i<=n;i++)cin>>A[i]; int u,v; for(int i=1;i<n;i++) { cin>>u>>v; G[u].pb(v); G[v].pb(u); } cin>>m; memset(add,0,sizeof add); memset(p,0,sizeof p); dfs(1,0); while(m--) { cin>>u>>v; int x=p[v]; if(u==1) { 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 0; }
相关文章推荐
- Backup Exec System Recovery Linux 版本
- Backup Exec System Recovery Disk进行异机还原
- How To Perform Oracle Solaris 11 System Backup And Recovery
- Symantec Backup Exec System Recovery还原向导
- BackupExec System Recovery 配置使用指导
- How To Backup Your Android Phone’s Boot, Recovery And System Partition Images -- RomDump
- Backup Exec System Recovery Disk进行异机还原
- Auto backup something with python in freebsd system
- Open Backup Device :Operating system error 5(error not found)
- ORA-00245: control file backup failed; target is likely on a local file system
- 服务器备份利器-Symantec Backup Exec System Recovery 2010绿色便携版 B1.0
- Symantec Backup Exec System Recovery简明安装手册
- ural 2030
- BackupExec System Recovery 配置使用指导
- UbuntuHelp:BackupYourSystem
- ORA-00245: control file backup failed; target is likely on a local file system
- Symantec Backup Exec System Recovery简明安装手册
- How to Backup Your System in linux
- Backup Exec System Recovery 6.5 初体验 推荐
- Symantec Backup Exec System Recovery还原向导